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 ?int $index = null;
  19.     private ?int $subIndex = null;
  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.     public function getIndex(): int
  42.     {
  43.         return $this->index;
  44.     }
  45.     public function setIndex(int $index): void
  46.     {
  47.         $this->index = $index;
  48.     }
  49.     public function getSubIndex(): int
  50.     {
  51.         return $this->subIndex;
  52.     }
  53.     public function setSubIndex(int $subIndex): void
  54.     {
  55.         $this->subIndex = $subIndex;
  56.     }
  57.     public function getLabel(): TranslatableInterface|string
  58.     {
  59.         return $this->label;
  60.     }
  61.     public function setLabel(TranslatableInterface|string $label): void
  62.     {
  63.         $this->label = $label;
  64.     }
  65.     public function getIcon(): ?string
  66.     {
  67.         return $this->icon;
  68.     }
  69.     public function setIcon(?string $icon): void
  70.     {
  71.         $this->icon = $icon;
  72.     }
  73.     public function getLinkUrl(): ?string
  74.     {
  75.         return $this->linkUrl;
  76.     }
  77.     public function setLinkUrl(?string $linkUrl): void
  78.     {
  79.         $this->linkUrl = $linkUrl;
  80.     }
  81.     public function getRouteName(): ?string
  82.     {
  83.         return $this->routeName;
  84.     }
  85.     public function setRouteName(?string $routeName): void
  86.     {
  87.         $this->routeName = $routeName;
  88.     }
  89.     public function getRouteParameters(): ?array
  90.     {
  91.         return $this->routeParameters;
  92.     }
  93.     public function setRouteParameter(string $parameterName, mixed $parameterValue): void
  94.     {
  95.         $this->routeParameters[$parameterName] = $parameterValue;
  96.     }
  97.     public function setRouteParameters(?array $routeParameters): void
  98.     {
  99.         $this->routeParameters = $routeParameters;
  100.     }
  101.     public function getPermission(): ?string
  102.     {
  103.         return $this->permission;
  104.     }
  105.     public function setPermission(?string $permission): void
  106.     {
  107.         $this->permission = $permission;
  108.     }
  109.     public function getCssClass(): string
  110.     {
  111.         return $this->cssClass;
  112.     }
  113.     public function setCssClass(string $cssClass): void
  114.     {
  115.         $this->cssClass = $cssClass;
  116.     }
  117.     public function getLinkRel(): string
  118.     {
  119.         return $this->linkRel;
  120.     }
  121.     public function setLinkRel(string $linkRel): void
  122.     {
  123.         $this->linkRel = $linkRel;
  124.     }
  125.     public function getLinkTarget(): string
  126.     {
  127.         return $this->linkTarget;
  128.     }
  129.     public function setLinkTarget(string $linkTarget): void
  130.     {
  131.         $this->linkTarget = $linkTarget;
  132.     }
  133.     public function getTranslationParameters(): array
  134.     {
  135.         return $this->translationParameters;
  136.     }
  137.     public function setTranslationParameters(array $translationParameters): void
  138.     {
  139.         $this->translationParameters = $translationParameters;
  140.     }
  141.     public function getBadge(): ?MenuItemBadgeDto
  142.     {
  143.         return $this->badge;
  144.     }
  145.     public function setBadge(mixed $content, string $style): void
  146.     {
  147.         $this->badge = new MenuItemBadgeDto($content, trim($style));
  148.     }
  149.     /**
  150.      * @return MenuItemDto[]
  151.      */
  152.     public function getSubItems(): array
  153.     {
  154.         return $this->subItems;
  155.     }
  156.     /**
  157.      * @param MenuItemDto[] $subItems
  158.      */
  159.     public function setSubItems(array $subItems): void
  160.     {
  161.         $this->subItems = $subItems;
  162.     }
  163.     public function hasSubItems(): bool
  164.     {
  165.         return self::TYPE_SUBMENU === $this->type && \count($this->subItems) > 0;
  166.     }
  167.     public function isMenuSection(): bool
  168.     {
  169.         return self::TYPE_SECTION === $this->type;
  170.     }
  171. }