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

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