From f44b7daf8c12c42d43323c7a9d45f4ef85954bab Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Sat, 21 Sep 2013 15:32:27 +0200 Subject: [PATCH] create content listener for crud management --- core/lib/Thelia/Action/Content.php | 90 +++++++++++++++++++++ core/lib/Thelia/Config/Resources/action.xml | 5 ++ 2 files changed, 95 insertions(+) create mode 100644 core/lib/Thelia/Action/Content.php diff --git a/core/lib/Thelia/Action/Content.php b/core/lib/Thelia/Action/Content.php new file mode 100644 index 000000000..1fa91fa15 --- /dev/null +++ b/core/lib/Thelia/Action/Content.php @@ -0,0 +1,90 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Action; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Thelia\Core\Event\Content\ContentUpdateEvent; +use Thelia\Core\Event\TheliaEvents; +use Thelia\Model\ContentQuery; + + +/** + * Class Content + * @package Thelia\Action + * @author manuel raynaud + */ +class Content extends BaseAction implements EventSubscriberInterface +{ + + public function update(ContentUpdateEvent $event) + { + if (null !== $content = ContentQuery::create()->findPk($event->getContentId())) { + $content->setDispatcher($this->getDispatcher()); + + $content + ->setVisible($event->getVisible()) + ->setLocale($event->getLocale()) + ->setTitle($event->getTitle()) + ->setDescription($event->getDescription()) + ->setChapo($event->getChapo()) + ->setPostscriptum($event->getPostscriptum()) + ->save() + ; + + $event->setContent($content); + } + } + + /** + * 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::CONTENT_CREATE => array("create", 128), + TheliaEvents::CONTENT_UPDATE => array("update", 128), + TheliaEvents::CONTENT_DELETE => array("delete", 128), + TheliaEvents::CONTENT_TOGGLE_VISIBILITY => array("toggleVisibility", 128), + + TheliaEvents::CONTENT_UPDATE_POSITION => array("updatePosition", 128), + ); + } + +} \ No newline at end of file diff --git a/core/lib/Thelia/Config/Resources/action.xml b/core/lib/Thelia/Config/Resources/action.xml index 801e68c6b..15839df95 100755 --- a/core/lib/Thelia/Config/Resources/action.xml +++ b/core/lib/Thelia/Config/Resources/action.xml @@ -102,6 +102,11 @@ + + + + +