vendor/sylius/sylius/src/Sylius/Bundle/AdminBundle/Twig/NotificationWidgetExtension.php line 49

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Sylius package.
  4.  *
  5.  * (c) Paweł Jędrzejewski
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. declare(strict_types=1);
  11. namespace Sylius\Bundle\AdminBundle\Twig;
  12. use Sylius\Bundle\CoreBundle\Application\Kernel;
  13. use Twig\Environment;
  14. use Twig\Extension\AbstractExtension;
  15. use Twig\TwigFunction;
  16. final class NotificationWidgetExtension extends AbstractExtension
  17. {
  18.     /** @var bool */
  19.     private $areNotificationsEnabled;
  20.     /** @var int */
  21.     private $checkFrequency;
  22.     public function __construct(bool $areNotificationsEnabledint $checkFrequency)
  23.     {
  24.         $this->areNotificationsEnabled $areNotificationsEnabled;
  25.         $this->checkFrequency $checkFrequency;
  26.     }
  27.     public function getFunctions(): array
  28.     {
  29.         return [
  30.             new TwigFunction(
  31.                 'sylius_render_notifications_widget',
  32.                 [$this'renderWidget'],
  33.                 [
  34.                     'needs_environment' => true,
  35.                     'is_safe' => ['html'],
  36.                 ]
  37.             ),
  38.         ];
  39.     }
  40.     public function renderWidget(Environment $environment): string
  41.     {
  42.         if (!$this->areNotificationsEnabled) {
  43.             return '';
  44.         }
  45.         return $environment->render('@SyliusAdmin/_notification.html.twig', [
  46.             'frequency' => $this->checkFrequency,
  47.             'currentVersion' => Kernel::VERSION,
  48.         ]);
  49.     }
  50. }