diff --git a/Form/Processor/ContentTypeFormProcessor.php b/Form/Processor/ContentTypeFormProcessor.php
index 34bd9d38a..1516d49d8 100644
--- a/Form/Processor/ContentTypeFormProcessor.php
+++ b/Form/Processor/ContentTypeFormProcessor.php
@@ -10,6 +10,8 @@
namespace EzSystems\PlatformUIBundle\Form\Processor;
use eZ\Publish\API\Repository\Values\ContentType\ContentTypeDraft;
+use EzSystems\PlatformUIBundle\Notification\NotificationPoolInterface;
+use EzSystems\PlatformUIBundle\Notification\TranslatableNotificationMessage;
use EzSystems\RepositoryForms\Event\FormActionEvent;
use EzSystems\RepositoryForms\Event\RepositoryFormEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@@ -23,19 +25,31 @@ class ContentTypeFormProcessor implements EventSubscriberInterface
*/
private $router;
- public function __construct(RouterInterface $router)
+ /**
+ * @var NotificationPoolInterface
+ */
+ private $notificationPool;
+
+ public function __construct(RouterInterface $router, NotificationPoolInterface $notificationPool)
{
$this->router = $router;
+ $this->notificationPool = $notificationPool;
}
public static function getSubscribedEvents()
{
return [
+ RepositoryFormEvents::CONTENT_TYPE_UPDATE => ['processDefaultAction', -10],
RepositoryFormEvents::CONTENT_TYPE_PUBLISH => ['processPublishContentType', -10],
RepositoryFormEvents::CONTENT_TYPE_REMOVE_DRAFT => ['processRemoveContentTypeDraft', -10],
];
}
+ public function processDefaultAction(FormActionEvent $event)
+ {
+ $this->addNotification('content_type.notification.draft_updated');
+ }
+
public function processPublishContentType(FormActionEvent $event)
{
$event->setResponse(
@@ -44,7 +58,8 @@ public function processPublishContentType(FormActionEvent $event)
$event->getOption('languageCode')
)
);
- // TODO: Add confirmation flash message.
+
+ $this->addNotification('content_type.notification.published');
}
public function processRemoveContentTypeDraft(FormActionEvent $event)
@@ -55,6 +70,8 @@ public function processRemoveContentTypeDraft(FormActionEvent $event)
$event->getOption('languageCode')
)
);
+
+ $this->addNotification('content_type.notification.draft_removed');
}
private function generateRedirectResponse(ContentTypeDraft $contentTypeDraft, $languageCode)
@@ -66,4 +83,12 @@ private function generateRedirectResponse(ContentTypeDraft $contentTypeDraft, $l
return new RedirectResponse($url);
}
+
+ private function addNotification($message)
+ {
+ $this->notificationPool->addNotification(new TranslatableNotificationMessage([
+ 'message' => $message,
+ 'domain' => 'content_type'
+ ]));
+ }
}
diff --git a/Notification/Notification.php b/Notification/Notification.php
new file mode 100644
index 000000000..9f220b457
--- /dev/null
+++ b/Notification/Notification.php
@@ -0,0 +1,42 @@
+translator = $translator;
+ $this->session = $session;
+ }
+
+ public static function getSubscribedEvents()
+ {
+ return [
+ KernelEvents::RESPONSE => 'onKernelResponse',
+ ];
+ }
+
+ public function addNotification(NotificationMessage $message, $state = Notification::STATE_DONE)
+ {
+ $translatedMessage = $message instanceof TranslatableNotificationMessage ? $this->translateMessage($message) : $message->message;
+ $this->notifications[] = new Notification([
+ 'message' => $translatedMessage,
+ 'state' => $state,
+ ]);
+ }
+
+ /**
+ * @return Notification[]
+ */
+ public function getNotifications()
+ {
+ return $this->notifications;
+ }
+
+ private function translateMessage(TranslatableNotificationMessage $message)
+ {
+ if ($message->number !== null) {
+ return $this->translator->transChoice(
+ $message->message,
+ (int)$message->number,
+ $message->translationParams,
+ $message->domain
+ );
+ }
+
+ return $this->translator->trans($message->message, $message->translationParams, $message->domain);
+ }
+
+ public function onKernelResponse(FilterResponseEvent $event)
+ {
+ $this->session->getFlashBag()->set('notification', $this->notifications);
+ }
+}
diff --git a/Notification/NotificationPoolInterface.php b/Notification/NotificationPoolInterface.php
new file mode 100644
index 000000000..1ad618051
--- /dev/null
+++ b/Notification/NotificationPoolInterface.php
@@ -0,0 +1,21 @@
+content_type.default_children_sorting
Default children sorting
+
+
+ The ContentType draft was successfully updated.
+
+
+
+ The ContentType draft was successfully removed.
+
+
+
+ The ContentType draft was successfully updated and published. Related Content has also been updated.
+