diff --git a/Controller/BreadcrumbController.php b/Controller/BreadcrumbController.php index f1a7bc9..741f0a6 100644 --- a/Controller/BreadcrumbController.php +++ b/Controller/BreadcrumbController.php @@ -32,6 +32,8 @@ class BreadcrumbController extends EmitterController */ public function breadcrumbAction(Request $request): Response { + @trigger_error('BreadcrumbController::breadcrumbAction() is deprecated and will be removed with 4.0', E_USER_DEPRECATED); + if (!$this->hasListener(BreadcrumbMenuEvent::class)) { return new Response(); } diff --git a/Controller/NavbarController.php b/Controller/NavbarController.php index b0a73eb..96882d9 100644 --- a/Controller/NavbarController.php +++ b/Controller/NavbarController.php @@ -21,24 +21,14 @@ class NavbarController extends EmitterController { /** - * @var int|null + * @var ContextHelper */ - private $maxNotifications; - /** - * @var int|null - */ - private $maxMessages; - /** - * @var int|null - */ - private $maxTasks; + private $helper; public function __construct(EventDispatcherInterface $dispatcher, ContextHelper $helper) { parent::__construct($dispatcher); - $this->maxNotifications = $helper->getOption('max_navbar_notifications'); - $this->maxMessages = $helper->getOption('max_navbar_messages'); - $this->maxTasks = $helper->getOption('max_navbar_tasks'); + $this->helper = $helper; } /** @@ -47,12 +37,14 @@ public function __construct(EventDispatcherInterface $dispatcher, ContextHelper */ public function notificationsAction($max = null): Response { + @trigger_error('NavbarController::notificationsAction() is deprecated and will be removed with 4.0', E_USER_DEPRECATED); + if (!$this->hasListener(NotificationListEvent::class)) { return new Response(); } if (null === $max) { - $max = (int) $this->maxNotifications; + $max = (int) $this->helper->getOption('max_navbar_notifications'); } /** @var NotificationListEvent $listEvent */ @@ -73,12 +65,14 @@ public function notificationsAction($max = null): Response */ public function messagesAction($max = null): Response { + @trigger_error('NavbarController::messagesAction() is deprecated and will be removed with 4.0', E_USER_DEPRECATED); + if (!$this->hasListener(MessageListEvent::class)) { return new Response(); } if (null === $max) { - $max = (int) $this->maxMessages; + $max = (int) $this->helper->getOption('max_navbar_messages'); } /** @var MessageListEvent $listEvent */ @@ -99,12 +93,14 @@ public function messagesAction($max = null): Response */ public function tasksAction($max = null): Response { + @trigger_error('NavbarController::tasksAction() is deprecated and will be removed with 4.0', E_USER_DEPRECATED); + if (!$this->hasListener(TaskListEvent::class)) { return new Response(); } if (null === $max) { - $max = (int) $this->maxTasks; + $max = (int) $this->helper->getOption('max_navbar_tasks'); } /** @var TaskListEvent $listEvent */ @@ -124,6 +120,8 @@ public function tasksAction($max = null): Response */ public function userAction(): Response { + @trigger_error('NavbarController::userAction() is deprecated and will be removed with 4.0', E_USER_DEPRECATED); + if (!$this->hasListener(NavbarUserEvent::class)) { return new Response(); } diff --git a/Controller/SidebarController.php b/Controller/SidebarController.php index c2099df..aa45c4c 100644 --- a/Controller/SidebarController.php +++ b/Controller/SidebarController.php @@ -15,13 +15,12 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -class SidebarController extends EmitterController +final class SidebarController extends EmitterController { - /** - * @return Response - */ public function userPanelAction(): Response { + @trigger_error('SidebarController::userPanelAction() is deprecated and will be removed with 4.0', E_USER_DEPRECATED); + if (!$this->hasListener(SidebarUserEvent::class)) { return new Response(); } @@ -37,20 +36,17 @@ public function userPanelAction(): Response ); } - /** - * @return Response - */ public function searchFormAction(): Response { + @trigger_error('SidebarController::searchFormAction() is deprecated and will be removed with 4.0', E_USER_DEPRECATED); + return $this->render('@AdminLTE/Sidebar/search-form.html.twig', []); } - /** - * @param Request $request - * @return Response - */ public function menuAction(Request $request): Response { + @trigger_error('SidebarController::menuAction() is deprecated and will be removed with 4.0', E_USER_DEPRECATED); + if (!$this->hasListener(SidebarMenuEvent::class)) { return new Response(); } diff --git a/Event/MenuEvent.php b/Event/MenuEvent.php index 1a39b3d..7e2077c 100644 --- a/Event/MenuEvent.php +++ b/Event/MenuEvent.php @@ -83,7 +83,7 @@ public function removeItem($item): MenuEvent */ public function getRootItem($id) { - return isset($this->menuRootItems[$id]) ? $this->menuRootItems[$id] : null; + return $this->menuRootItems[$id] ?? null; } /** diff --git a/Event/MessageListEvent.php b/Event/MessageListEvent.php index a2c547c..2835bc6 100644 --- a/Event/MessageListEvent.php +++ b/Event/MessageListEvent.php @@ -10,11 +10,12 @@ namespace KevinPapst\AdminLTEBundle\Event; use KevinPapst\AdminLTEBundle\Model\MessageInterface; +use KevinPapst\AdminLTEBundle\Repository\MessageRepositoryInterface; /** * The MessageListEvent collects all MessageInterface objects that should be rendered in the messages section. */ -class MessageListEvent extends ThemeEvent +class MessageListEvent extends ThemeEvent implements MessageRepositoryInterface { /** * Stores the list of messages diff --git a/Event/NotificationListEvent.php b/Event/NotificationListEvent.php index 063d0cc..9197b3f 100644 --- a/Event/NotificationListEvent.php +++ b/Event/NotificationListEvent.php @@ -10,11 +10,12 @@ namespace KevinPapst\AdminLTEBundle\Event; use KevinPapst\AdminLTEBundle\Model\NotificationInterface; +use KevinPapst\AdminLTEBundle\Repository\NotificationRepositoryInterface; /** * The NotificationListEvent collects all NotificationInterface objects that should be rendered in the notification section. */ -class NotificationListEvent extends ThemeEvent +class NotificationListEvent extends ThemeEvent implements NotificationRepositoryInterface { /** * @var array diff --git a/Event/ShowUserEvent.php b/Event/ShowUserEvent.php index 1443ad2..5cf059b 100644 --- a/Event/ShowUserEvent.php +++ b/Event/ShowUserEvent.php @@ -10,12 +10,13 @@ namespace KevinPapst\AdminLTEBundle\Event; use KevinPapst\AdminLTEBundle\Model\NavBarUserLink; +use KevinPapst\AdminLTEBundle\Model\UserDetailsInterface; use KevinPapst\AdminLTEBundle\Model\UserInterface; /** * Collect the UserInterface object that should be rendered in the user section. */ -abstract class ShowUserEvent extends ThemeEvent +abstract class ShowUserEvent extends ThemeEvent implements UserDetailsInterface { /** * @var UserInterface diff --git a/Event/TaskListEvent.php b/Event/TaskListEvent.php index 1eca42d..c9c7e6d 100644 --- a/Event/TaskListEvent.php +++ b/Event/TaskListEvent.php @@ -10,11 +10,12 @@ namespace KevinPapst\AdminLTEBundle\Event; use KevinPapst\AdminLTEBundle\Model\TaskInterface; +use KevinPapst\AdminLTEBundle\Repository\TaskRepositoryInterface; /** * The TaskListEvent collects all TaskInterface objects that should be rendered in the tasks section. */ -class TaskListEvent extends ThemeEvent +class TaskListEvent extends ThemeEvent implements TaskRepositoryInterface { /** * @var TaskInterface[] @@ -32,7 +33,7 @@ class TaskListEvent extends ThemeEvent protected $total = 0; /** - * @param int $max Maximun number of tasks displayed in panel + * @param int|null $max Maximum number of tasks displayed in panel */ public function __construct($max = null) { @@ -50,7 +51,7 @@ public function getMax() } /** - * @return array + * @return TaskInterface[] */ public function getTasks() { diff --git a/Model/NotificationModel.php b/Model/NotificationModel.php index 51061ec..9a07a2c 100644 --- a/Model/NotificationModel.php +++ b/Model/NotificationModel.php @@ -14,27 +14,24 @@ class NotificationModel implements NotificationInterface { /** - * @return string + * @var string */ protected $type = Constants::TYPE_INFO; - /** - * @return string + * @var string */ protected $message; - /** - * @return string + * @var string */ protected $icon; - /** * @var string */ protected $id; /** - * @param string $message + * @param string|null $message * @param string $type * @param string $icon */ diff --git a/Model/UserDetailsInterface.php b/Model/UserDetailsInterface.php new file mode 100644 index 0000000..3d5c123 --- /dev/null +++ b/Model/UserDetailsInterface.php @@ -0,0 +1,24 @@ += 4.3 - Version 2.x of this bundle is compatible with Symfony < 4.3 diff --git a/Repository/MessageRepositoryInterface.php b/Repository/MessageRepositoryInterface.php new file mode 100644 index 0000000..be3dd27 --- /dev/null +++ b/Repository/MessageRepositoryInterface.php @@ -0,0 +1,25 @@ + + */ + public function getMessages(); +} diff --git a/Repository/NotificationRepositoryInterface.php b/Repository/NotificationRepositoryInterface.php new file mode 100644 index 0000000..029dddf --- /dev/null +++ b/Repository/NotificationRepositoryInterface.php @@ -0,0 +1,25 @@ + + */ + public function getNotifications(); +} diff --git a/Repository/TaskRepositoryInterface.php b/Repository/TaskRepositoryInterface.php new file mode 100644 index 0000000..24867f5 --- /dev/null +++ b/Repository/TaskRepositoryInterface.php @@ -0,0 +1,25 @@ + + */ + public function getTasks(); +} diff --git a/Resources/config/services.yml b/Resources/config/services.yml index 5697339..c08b009 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -5,17 +5,29 @@ services: tags: ['controller.service_arguments'] autowire: true - KevinPapst\AdminLTEBundle\Twig\AdminExtension: - class: KevinPapst\AdminLTEBundle\Twig\AdminExtension + KevinPapst\AdminLTEBundle\Twig\RuntimeExtension: + class: KevinPapst\AdminLTEBundle\Twig\RuntimeExtension arguments: - '@admin_lte_theme.context_helper' - '%admin_lte_theme.routes%' + tags: + - { name: twig.runtime } + + KevinPapst\AdminLTEBundle\Twig\EventsExtension: + class: KevinPapst\AdminLTEBundle\Twig\EventsExtension + arguments: + - '@event_dispatcher' + - '@admin_lte_theme.context_helper' + tags: + - { name: twig.runtime } + + KevinPapst\AdminLTEBundle\Twig\AdminExtension: + class: KevinPapst\AdminLTEBundle\Twig\AdminExtension tags: - { name: twig.extension } admin_lte_theme.context_helper: class: KevinPapst\AdminLTEBundle\Helper\ContextHelper - alias: arguments: - '%admin_lte_theme.options%' diff --git a/Resources/views/Breadcrumb/breadcrumb.html.twig b/Resources/views/Breadcrumb/breadcrumb.html.twig index 12a0e88..0521e79 100644 --- a/Resources/views/Breadcrumb/breadcrumb.html.twig +++ b/Resources/views/Breadcrumb/breadcrumb.html.twig @@ -1,3 +1,7 @@ +{% if active is not defined or adminlte_direct_include is defined %} + {% set active = adminlte_breadcrumbs(app.request) %} +{% endif %} +{% if active is defined and active is not null %} \ No newline at end of file + +{% endif %} \ No newline at end of file diff --git a/Resources/views/Navbar/messages.html.twig b/Resources/views/Navbar/messages.html.twig index c32d17e..0deec0d 100644 --- a/Resources/views/Navbar/messages.html.twig +++ b/Resources/views/Navbar/messages.html.twig @@ -1,11 +1,19 @@ {% import "@AdminLTE/Macros/default.html.twig" as macro %} +{% if messages is not defined or adminlte_direct_include is defined %} + {% set adminlte_messages = adminlte_messages() %} + {% if adminlte_messages is not null %} + {% set messages = adminlte_messages.messages %} + {% set total = adminlte_messages.total %} + {% endif %} +{% endif %} +{% if messages is defined and messages is not null %}