process folder update action
This commit is contained in:
91
core/lib/Thelia/Action/Folder.php
Normal file
91
core/lib/Thelia/Action/Folder.php
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
<?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\Action;
|
||||||
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||||
|
use Thelia\Core\Event\FolderUpdateEvent;
|
||||||
|
use Thelia\Core\Event\TheliaEvents;
|
||||||
|
use Thelia\Model\FolderQuery;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Folder
|
||||||
|
* @package Thelia\Action
|
||||||
|
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||||
|
*/
|
||||||
|
class Folder extends BaseAction implements EventSubscriberInterface {
|
||||||
|
|
||||||
|
|
||||||
|
public function update(FolderUpdateEvent $event)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (null !== $folder = FolderQuery::create()->findPk($event->getFolderId())) {
|
||||||
|
$folder->setDispatcher($this->getDispatcher());
|
||||||
|
|
||||||
|
$folder
|
||||||
|
->setParent($event->getParent())
|
||||||
|
->setVisible($event->getVisible())
|
||||||
|
->setLocale($event->getLocale())
|
||||||
|
->setTitle($event->getTitle())
|
||||||
|
->setDescription($event->getDescription())
|
||||||
|
->setChapo($event->getChapo())
|
||||||
|
->setPostscriptum($event->getPostscriptum())
|
||||||
|
->save();
|
||||||
|
;
|
||||||
|
|
||||||
|
$event->setFolder($folder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an array of event names this subscriber wants to listen to.
|
||||||
|
*
|
||||||
|
* The array keys are event names and the value can be:
|
||||||
|
*
|
||||||
|
* * The method name to call (priority defaults to 0)
|
||||||
|
* * An array composed of the method name to call and the priority
|
||||||
|
* * An array of arrays composed of the method names to call and respective
|
||||||
|
* priorities, or 0 if unset
|
||||||
|
*
|
||||||
|
* For instance:
|
||||||
|
*
|
||||||
|
* * array('eventName' => 'methodName')
|
||||||
|
* * array('eventName' => array('methodName', $priority))
|
||||||
|
* * array('eventName' => array(array('methodName1', $priority), array('methodName2'))
|
||||||
|
*
|
||||||
|
* @return array The event names to listen to
|
||||||
|
*
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
public static function getSubscribedEvents()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
TheliaEvents::FOLDER_CREATE => array("create", 128),
|
||||||
|
TheliaEvents::FOLDER_UPDATE => array("update", 128),
|
||||||
|
TheliaEvents::FOLDER_DELETE => array("delete", 128),
|
||||||
|
TheliaEvents::FOLDER_TOGGLE_VISIBILITY => array("toggleVisibility", 128),
|
||||||
|
|
||||||
|
TheliaEvents::FOLDER_UPDATE_POSITION => array("updatePosition", 128),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -97,6 +97,11 @@
|
|||||||
<tag name="kernel.event_subscriber"/>
|
<tag name="kernel.event_subscriber"/>
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
|
<service id="thelia.action.folder" class="Thelia\Action\Folder">
|
||||||
|
<argument type="service" id="service_container"/>
|
||||||
|
<tag name="kernel.event_subscriber"/>
|
||||||
|
</service>
|
||||||
|
|
||||||
</services>
|
</services>
|
||||||
|
|
||||||
</config>
|
</config>
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ class FolderController extends AbstractCrudController
|
|||||||
*/
|
*/
|
||||||
protected function eventContainsObject($event)
|
protected function eventContainsObject($event)
|
||||||
{
|
{
|
||||||
// TODO: Implement eventContainsObject() method.
|
return $event->hasFolder();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -170,9 +170,8 @@ class FolderController extends AbstractCrudController
|
|||||||
*
|
*
|
||||||
* @param unknown $object
|
* @param unknown $object
|
||||||
*/
|
*/
|
||||||
protected function getObjectLabel($object)
|
protected function getObjectLabel($object) {
|
||||||
{
|
return $object->getTitle();
|
||||||
// TODO: Implement getObjectLabel() method.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -182,7 +181,7 @@ class FolderController extends AbstractCrudController
|
|||||||
*/
|
*/
|
||||||
protected function getObjectId($object)
|
protected function getObjectId($object)
|
||||||
{
|
{
|
||||||
// TODO: Implement getObjectId() method.
|
return $object->getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -220,12 +219,37 @@ class FolderController extends AbstractCrudController
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \Thelia\Core\Event\FolderUpdateEvent $updateEvent
|
||||||
|
* @return Response|void
|
||||||
|
*/
|
||||||
|
protected function performAdditionalUpdateAction($updateEvent)
|
||||||
|
{
|
||||||
|
if ($this->getRequest()->get('save_mode') != 'stay') {
|
||||||
|
|
||||||
|
// Redirect to parent category list
|
||||||
|
$this->redirectToRoute(
|
||||||
|
'admin.folders.default',
|
||||||
|
array('folder_id' => $updateEvent->getFolder()->getParent())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function performAdditionalDeleteAction($deleteEvent)
|
||||||
|
{
|
||||||
|
// Redirect to parent category list
|
||||||
|
$this->redirectToRoute(
|
||||||
|
'admin.folders.default',
|
||||||
|
array('folder_id' => $deleteEvent->getFolder()->getParent())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Redirect to the edition template
|
* Redirect to the edition template
|
||||||
*/
|
*/
|
||||||
protected function redirectToEditionTemplate()
|
protected function redirectToEditionTemplate()
|
||||||
{
|
{
|
||||||
// TODO: Implement redirectToEditionTemplate() method.
|
$this->redirectToRoute("admin.folders.update", $this->getEditionArguments());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -233,6 +257,9 @@ class FolderController extends AbstractCrudController
|
|||||||
*/
|
*/
|
||||||
protected function redirectToListTemplate()
|
protected function redirectToListTemplate()
|
||||||
{
|
{
|
||||||
// TODO: Implement redirectToListTemplate() method.
|
$this->redirectToRoute(
|
||||||
|
'admin.folders.default',
|
||||||
|
array('folder_id' => $this->getRequest()->get('folder_id', 0))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -67,7 +67,7 @@
|
|||||||
{form_hidden_fields form=$form}
|
{form_hidden_fields form=$form}
|
||||||
|
|
||||||
{form_field form=$form field='success_url'}
|
{form_field form=$form field='success_url'}
|
||||||
<input type="hidden" name="{$name}" value="{url path='/admin/folder' folder_id={$folder_id}}" />
|
<input type="hidden" name="{$name}" value="{url path='/admin/folders/update' folder_id={$folder_id}}" />
|
||||||
{/form_field}
|
{/form_field}
|
||||||
|
|
||||||
{form_field form=$form field='locale'}
|
{form_field form=$form field='locale'}
|
||||||
|
|||||||
Reference in New Issue
Block a user