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

Open in your IDE?
  1. <?php
  2. namespace EasyCorp\Bundle\EasyAdminBundle\Dto;
  3. use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
  4. /**
  5.  * @author Javier Eguiluz <javier.eguiluz@gmail.com>
  6.  */
  7. final class ActionDto
  8. {
  9.     private $type;
  10.     private $name;
  11.     private $label;
  12.     private $icon;
  13.     private $cssClass;
  14.     private $htmlElement;
  15.     private $htmlAttributes;
  16.     private $linkUrl;
  17.     private $templatePath;
  18.     private $crudActionName;
  19.     private $routeName;
  20.     private $routeParameters;
  21.     private $url;
  22.     private $translationParameters;
  23.     private $displayCallable;
  24.     public function __construct()
  25.     {
  26.         $this->cssClass '';
  27.         $this->htmlAttributes = [];
  28.         $this->routeParameters = [];
  29.         $this->translationParameters = [];
  30.     }
  31.     public function getType(): string
  32.     {
  33.         return $this->type;
  34.     }
  35.     public function setType(string $type): void
  36.     {
  37.         $this->type $type;
  38.     }
  39.     public function isEntityAction(): bool
  40.     {
  41.         return Action::TYPE_ENTITY === $this->type;
  42.     }
  43.     public function isGlobalAction(): bool
  44.     {
  45.         return Action::TYPE_GLOBAL === $this->type;
  46.     }
  47.     public function isBatchAction(): bool
  48.     {
  49.         return Action::TYPE_BATCH === $this->type;
  50.     }
  51.     public function getName(): string
  52.     {
  53.         return $this->name;
  54.     }
  55.     public function setName(string $name): void
  56.     {
  57.         $this->name $name;
  58.     }
  59.     /**
  60.      * @return string|false|null
  61.      */
  62.     public function getLabel()
  63.     {
  64.         return $this->label;
  65.     }
  66.     public function setLabel(?string $label): void
  67.     {
  68.         $this->label $label;
  69.     }
  70.     public function getIcon(): ?string
  71.     {
  72.         return $this->icon;
  73.     }
  74.     public function setIcon(?string $icon): void
  75.     {
  76.         $this->icon $icon;
  77.     }
  78.     public function getCssClass(): string
  79.     {
  80.         return $this->cssClass;
  81.     }
  82.     public function setCssClass(string $cssClass): void
  83.     {
  84.         $this->cssClass $cssClass;
  85.     }
  86.     public function getHtmlElement(): string
  87.     {
  88.         return $this->htmlElement;
  89.     }
  90.     public function setHtmlElement(string $htmlElement): void
  91.     {
  92.         $this->htmlElement $htmlElement;
  93.     }
  94.     public function getHtmlAttributes(): array
  95.     {
  96.         return $this->htmlAttributes;
  97.     }
  98.     public function addHtmlAttributes(array $htmlAttributes): void
  99.     {
  100.         $this->htmlAttributes array_merge($this->htmlAttributes$htmlAttributes);
  101.     }
  102.     public function setHtmlAttributes(array $htmlAttributes): void
  103.     {
  104.         $this->htmlAttributes $htmlAttributes;
  105.     }
  106.     public function setHtmlAttribute(string $attributeNamestring $attributeValue): void
  107.     {
  108.         $this->htmlAttributes[$attributeName] = $attributeValue;
  109.     }
  110.     public function getTemplatePath(): ?string
  111.     {
  112.         return $this->templatePath;
  113.     }
  114.     public function setTemplatePath(string $templatePath): void
  115.     {
  116.         $this->templatePath $templatePath;
  117.     }
  118.     public function getLinkUrl(): string
  119.     {
  120.         return $this->linkUrl;
  121.     }
  122.     public function setLinkUrl(string $linkUrl): void
  123.     {
  124.         $this->linkUrl $linkUrl;
  125.     }
  126.     public function getCrudActionName(): ?string
  127.     {
  128.         return $this->crudActionName;
  129.     }
  130.     public function setCrudActionName(string $crudActionName): void
  131.     {
  132.         $this->crudActionName $crudActionName;
  133.     }
  134.     public function getRouteName(): ?string
  135.     {
  136.         return $this->routeName;
  137.     }
  138.     public function setRouteName(string $routeName): void
  139.     {
  140.         $this->routeName $routeName;
  141.     }
  142.     /**
  143.      * @return array|callable
  144.      */
  145.     public function getRouteParameters()
  146.     {
  147.         return $this->routeParameters;
  148.     }
  149.     /**
  150.      * @param array|callable $routeParameters
  151.      */
  152.     public function setRouteParameters($routeParameters): void
  153.     {
  154.         $this->routeParameters $routeParameters;
  155.     }
  156.     /**
  157.      * @return string|callable
  158.      */
  159.     public function getUrl()
  160.     {
  161.         return $this->url;
  162.     }
  163.     /**
  164.      * @param string|callable $url
  165.      */
  166.     public function setUrl($url): void
  167.     {
  168.         $this->url $url;
  169.     }
  170.     public function getTranslationParameters(): array
  171.     {
  172.         return $this->translationParameters;
  173.     }
  174.     public function setTranslationParameters(array $translationParameters): void
  175.     {
  176.         $this->translationParameters $translationParameters;
  177.     }
  178.     public function shouldBeDisplayedFor(EntityDto $entityDto): bool
  179.     {
  180.         return null === $this->displayCallable || \call_user_func($this->displayCallable$entityDto->getInstance());
  181.     }
  182.     public function setDisplayCallable(callable $displayCallable): void
  183.     {
  184.         $this->displayCallable $displayCallable;
  185.     }
  186.     /**
  187.      * @internal
  188.      */
  189.     public function getAsConfigObject(): Action
  190.     {
  191.         $action Action::new($this->name$this->label$this->icon);
  192.         $action->setCssClass($this->cssClass);
  193.         $action->setHtmlAttributes($this->htmlAttributes);
  194.         $action->setTranslationParameters($this->translationParameters);
  195.         if (null !== $this->templatePath) {
  196.             $action->setTemplatePath($this->templatePath);
  197.         }
  198.         if ($this->isGlobalAction()) {
  199.             $action->createAsGlobalAction();
  200.         } elseif ($this->isBatchAction()) {
  201.             $action->createAsBatchAction();
  202.         }
  203.         if ('a' === $this->htmlElement) {
  204.             $action->displayAsLink();
  205.         } else {
  206.             $action->displayAsButton();
  207.         }
  208.         if (null !== $this->crudActionName) {
  209.             $action->linkToCrudAction($this->crudActionName);
  210.         }
  211.         if (null !== $this->routeName) {
  212.             $action->linkToRoute($this->routeName$this->routeParameters);
  213.         }
  214.         if (null !== $this->displayCallable) {
  215.             $action->displayIf($this->displayCallable);
  216.         }
  217.         return $action;
  218.     }
  219. }