vendor/easycorp/easyadmin-bundle/src/Dto/MenuItemDto.php line 11

Open in your IDE?
  1. <?php
  2. namespace EasyCorp\Bundle\EasyAdminBundle\Dto;
  3. use Symfony\Component\ExpressionLanguage\Expression;
  4. use Symfony\Contracts\Translation\TranslatableInterface;
  5. /**
  6.  * @author Javier Eguiluz <javier.eguiluz@gmail.com>
  7.  */
  8. final class MenuItemDto
  9. {
  10.     public const TYPE_CRUD 'crud';
  11.     public const TYPE_URL 'url';
  12.     public const TYPE_SECTION 'section';
  13.     public const TYPE_EXIT_IMPERSONATION 'exit_impersonation';
  14.     public const TYPE_DASHBOARD 'dashboard';
  15.     public const TYPE_LOGOUT 'logout';
  16.     public const TYPE_SUBMENU 'submenu';
  17.     public const TYPE_ROUTE 'route';
  18.     private ?string $type null;
  19.     private bool $selected false;
  20.     private bool $expanded false;
  21.     private TranslatableInterface|string|null $label null;
  22.     private ?string $icon null;
  23.     private string $cssClass '';
  24.     private string|Expression|null $permission null;
  25.     private ?string $routeName null;
  26.     private ?array $routeParameters null;
  27.     private ?string $linkUrl null;
  28.     private string $linkRel '';
  29.     private string $linkTarget '_self';
  30.     private array $translationParameters = [];
  31.     private ?MenuItemBadgeDto $badge null;
  32.     /** @var MenuItemDto[] */
  33.     private array $subItems = [];
  34.     private array $htmlAttributes = [];
  35.     public function getType(): string
  36.     {
  37.         return $this->type;
  38.     }
  39.     public function setType(string $type): void
  40.     {
  41.         $this->type $type;
  42.     }
  43.     /** @deprecated This was used in the past to get the selected menu item
  44.      *              Now the active menu item is detected automatically via the Request data
  45.      */
  46.     public function getIndex(): int
  47.     {
  48.         return -1;
  49.     }
  50.     /** @deprecated This was used in the past to set the selected menu item
  51.      *              Now the active menu item is detected automatically via the Request data
  52.      */
  53.     public function setIndex(int $index): void
  54.     {
  55.         // do nothing...
  56.     }
  57.     /** @deprecated This was used in the past to get the selected menu subitem
  58.      *              Now the active menu item is detected automatically via the Request data
  59.      */
  60.     public function getSubIndex(): int
  61.     {
  62.         return -1;
  63.     }
  64.     /** @deprecated This was used in the past to set the selected menu subitem
  65.      *              Now the active menu item is detected automatically via the Request data
  66.      */
  67.     public function setSubIndex(int $subIndex): void
  68.     {
  69.         // do nothing
  70.     }
  71.     /**
  72.      * @return bool Returns true when this menu item is the selected one
  73.      */
  74.     public function isSelected(): bool
  75.     {
  76.         return $this->selected;
  77.     }
  78.     public function setSelected(bool $isSelected): void
  79.     {
  80.         $this->selected $isSelected;
  81.     }
  82.     /**
  83.      * @return bool Returns true when any of its subitems is selected
  84.      */
  85.     public function isExpanded(): bool
  86.     {
  87.         return $this->expanded;
  88.     }
  89.     public function setExpanded(bool $isExpanded): void
  90.     {
  91.         $this->expanded $isExpanded;
  92.     }
  93.     public function getLabel(): TranslatableInterface|string
  94.     {
  95.         return $this->label;
  96.     }
  97.     public function setLabel(TranslatableInterface|string $label): void
  98.     {
  99.         $this->label $label;
  100.     }
  101.     public function getIcon(): ?string
  102.     {
  103.         return $this->icon;
  104.     }
  105.     public function setIcon(?string $icon): void
  106.     {
  107.         $this->icon $icon;
  108.     }
  109.     public function getLinkUrl(): ?string
  110.     {
  111.         return $this->linkUrl;
  112.     }
  113.     public function setLinkUrl(?string $linkUrl): void
  114.     {
  115.         $this->linkUrl $linkUrl;
  116.     }
  117.     public function getRouteName(): ?string
  118.     {
  119.         return $this->routeName;
  120.     }
  121.     public function setRouteName(?string $routeName): void
  122.     {
  123.         $this->routeName $routeName;
  124.     }
  125.     public function getRouteParameters(): ?array
  126.     {
  127.         return $this->routeParameters;
  128.     }
  129.     public function setRouteParameter(string $parameterNamemixed $parameterValue): void
  130.     {
  131.         $this->routeParameters[$parameterName] = $parameterValue;
  132.     }
  133.     public function setRouteParameters(?array $routeParameters): void
  134.     {
  135.         $this->routeParameters $routeParameters;
  136.     }
  137.     public function getPermission(): string|Expression|null
  138.     {
  139.         return $this->permission;
  140.     }
  141.     public function setPermission(string|Expression|null $permission): void
  142.     {
  143.         $this->permission $permission;
  144.     }
  145.     public function getCssClass(): string
  146.     {
  147.         return $this->cssClass;
  148.     }
  149.     public function setCssClass(string $cssClass): void
  150.     {
  151.         $this->cssClass $cssClass;
  152.     }
  153.     public function getLinkRel(): string
  154.     {
  155.         return $this->linkRel;
  156.     }
  157.     public function setLinkRel(string $linkRel): void
  158.     {
  159.         $this->linkRel $linkRel;
  160.     }
  161.     public function getLinkTarget(): string
  162.     {
  163.         return $this->linkTarget;
  164.     }
  165.     public function setLinkTarget(string $linkTarget): void
  166.     {
  167.         $this->linkTarget $linkTarget;
  168.     }
  169.     public function getTranslationParameters(): array
  170.     {
  171.         return $this->translationParameters;
  172.     }
  173.     public function setTranslationParameters(array $translationParameters): void
  174.     {
  175.         $this->translationParameters $translationParameters;
  176.     }
  177.     public function getBadge(): ?MenuItemBadgeDto
  178.     {
  179.         return $this->badge;
  180.     }
  181.     public function setBadge(mixed $contentstring $style, array $htmlAttributes = []): void
  182.     {
  183.         $this->badge = new MenuItemBadgeDto($contenttrim($style), $htmlAttributes);
  184.     }
  185.     /**
  186.      * @return MenuItemDto[]
  187.      */
  188.     public function getSubItems(): array
  189.     {
  190.         return $this->subItems;
  191.     }
  192.     /**
  193.      * @param MenuItemDto[] $subItems
  194.      */
  195.     public function setSubItems(array $subItems): void
  196.     {
  197.         $this->subItems $subItems;
  198.     }
  199.     public function hasSubItems(): bool
  200.     {
  201.         return self::TYPE_SUBMENU === $this->type && \count($this->subItems) > 0;
  202.     }
  203.     public function isMenuSection(): bool
  204.     {
  205.         return self::TYPE_SECTION === $this->type;
  206.     }
  207.     public function getHtmlAttributes(): array
  208.     {
  209.         return $this->htmlAttributes;
  210.     }
  211.     public function setHtmlAttribute(string $attributemixed $value): void
  212.     {
  213.         $this->htmlAttributes[$attribute] = $value;
  214.     }
  215. }