create removeAdditionalFolder controller, event and listener
This commit is contained in:
@@ -27,6 +27,7 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Thelia\Core\Event\Content\ContentAddFolderEvent;
|
||||
use Thelia\Core\Event\Content\ContentCreateEvent;
|
||||
use Thelia\Core\Event\Content\ContentDeleteEvent;
|
||||
use Thelia\Core\Event\Content\ContentRemoveFolderEvent;
|
||||
use Thelia\Core\Event\Content\ContentToggleVisibilityEvent;
|
||||
use Thelia\Core\Event\Content\ContentUpdateEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
@@ -127,6 +128,12 @@ class Content extends BaseAction implements EventSubscriberInterface
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* associate a folder to a content if the association already does not exists
|
||||
*
|
||||
* @param ContentAddFolderEvent $event
|
||||
*/
|
||||
public function addFolder(ContentAddFolderEvent $event)
|
||||
{
|
||||
if(ContentFolderQuery::create()
|
||||
@@ -144,6 +151,18 @@ class Content extends BaseAction implements EventSubscriberInterface
|
||||
}
|
||||
}
|
||||
|
||||
public function removeFolder(ContentRemoveFolderEvent $event)
|
||||
{
|
||||
$contentFolder = ContentFolderQuery::create()
|
||||
->filterByContent($event->getContent())
|
||||
->filterByFolderId($event->getFolderId())
|
||||
->findOne();
|
||||
|
||||
if(null !== $contentFolder) {
|
||||
$contentFolder->delete();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of event names this subscriber wants to listen to.
|
||||
*
|
||||
|
||||
@@ -396,11 +396,11 @@
|
||||
</route>
|
||||
|
||||
<route id="admin.content.additional-folder.add" path="/admin/products/category/add">
|
||||
<default key="_controller">Thelia\Controller\Admin\ContentController::addAdditionalCategoryAction</default>
|
||||
<default key="_controller">Thelia\Controller\Admin\ContentController::addAdditionalFolderAction</default>
|
||||
</route>
|
||||
|
||||
<route id="admin.content.additional-folder.delete" path="/admin/products/category/delete">
|
||||
<default key="_controller">Thelia\Controller\Admin\ContentController::deleteAdditionalCategoryAction</default>
|
||||
<default key="_controller">Thelia\Controller\Admin\ContentController::removeAdditionalFolderAction</default>
|
||||
</route>
|
||||
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ namespace Thelia\Controller\Admin;
|
||||
use Thelia\Core\Event\Content\ContentAddFolderEvent;
|
||||
use Thelia\Core\Event\Content\ContentCreateEvent;
|
||||
use Thelia\Core\Event\Content\ContentDeleteEvent;
|
||||
use Thelia\Core\Event\Content\ContentRemoveFolderEvent;
|
||||
use Thelia\Core\Event\Content\ContentToggleVisibilityEvent;
|
||||
use Thelia\Core\Event\Content\ContentUpdateEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
@@ -61,6 +62,11 @@ class ContentController extends AbstractCrudController
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* controller adding content to additional folder
|
||||
*
|
||||
* @return mixed|\Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function addAdditionalFolderAction()
|
||||
{
|
||||
// Check current user authorization
|
||||
@@ -75,12 +81,41 @@ class ContentController extends AbstractCrudController
|
||||
);
|
||||
|
||||
try {
|
||||
|
||||
$this->dispatch(TheliaEvents::CONTENT_ADD_FOLDER, $event);
|
||||
} catch (\Exception $e) {
|
||||
$this->errorPage($e);
|
||||
return $this->errorPage($e);
|
||||
}
|
||||
}
|
||||
|
||||
$this->redirectToEditionTemplate();
|
||||
}
|
||||
|
||||
/**
|
||||
* controller removing additional folder to a content
|
||||
*
|
||||
* @return mixed|\Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function removeAdditionalFolderAction()
|
||||
{
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth('admin.content.update')) return $response;
|
||||
|
||||
$folder_id = intval($this->getRequest()->request->get('additional_folder_id'));
|
||||
|
||||
if ($folder_id > 0) {
|
||||
$event = new ContentRemoveFolderEvent(
|
||||
$this->getExistingObject(),
|
||||
$folder_id
|
||||
);
|
||||
|
||||
try {
|
||||
$this->dispatch(TheliaEvents::CONTENT_REMOVE_FOLDER, $event);
|
||||
} catch (\Exception $e) {
|
||||
return $this->errorPage($e);
|
||||
}
|
||||
}
|
||||
|
||||
$this->redirectToEditionTemplate();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Core\Event\Content;
|
||||
|
||||
|
||||
/**
|
||||
* Class ContentRemoveFolderEvent
|
||||
* @package Thelia\Core\Event\Content
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class ContentRemoveFolderEvent extends ContentAddFolderEvent
|
||||
{
|
||||
}
|
||||
Reference in New Issue
Block a user