vendor/easycorp/easyadmin-bundle/src/Dto/FieldDto.php line 13

Open in your IDE?
  1. <?php
  2. namespace EasyCorp\Bundle\EasyAdminBundle\Dto;
  3. use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
  4. use EasyCorp\Bundle\EasyAdminBundle\Config\KeyValueStore;
  5. use function Symfony\Component\String\u;
  6. use Symfony\Component\Uid\Ulid;
  7. /**
  8.  * @author Javier Eguiluz <javier.eguiluz@gmail.com>
  9.  */
  10. final class FieldDto
  11. {
  12.     private $fieldFqcn;
  13.     private $propertyName;
  14.     private $value;
  15.     private $formattedValue;
  16.     private $formatValueCallable;
  17.     private $label;
  18.     private $formType;
  19.     private $formTypeOptions;
  20.     private $sortable;
  21.     private $virtual;
  22.     private $permission;
  23.     private $textAlign;
  24.     private $help;
  25.     private $cssClass;
  26.     private $translationParameters;
  27.     private $templateName;
  28.     private $templatePath;
  29.     /** @var AssetsDto */
  30.     private $assets;
  31.     private $customOptions;
  32.     private $doctrineMetadata;
  33.     /** @internal */
  34.     private $uniqueId;
  35.     private $displayedOn;
  36.     public function __construct()
  37.     {
  38.         $this->cssClass '';
  39.         $this->templateName 'crud/field/text';
  40.         $this->assets = new AssetsDto();
  41.         $this->translationParameters = [];
  42.         $this->formTypeOptions KeyValueStore::new();
  43.         $this->customOptions KeyValueStore::new();
  44.         $this->doctrineMetadata KeyValueStore::new();
  45.         $this->displayedOn KeyValueStore::new([
  46.             Crud::PAGE_INDEX => Crud::PAGE_INDEX,
  47.             Crud::PAGE_DETAIL => Crud::PAGE_DETAIL,
  48.             Crud::PAGE_EDIT => Crud::PAGE_EDIT,
  49.             Crud::PAGE_NEW => Crud::PAGE_NEW,
  50.         ]);
  51.     }
  52.     public function __clone()
  53.     {
  54.         $this->assets = clone $this->assets;
  55.         $this->formTypeOptions = clone $this->formTypeOptions;
  56.         $this->customOptions = clone $this->customOptions;
  57.         $this->doctrineMetadata = clone $this->doctrineMetadata;
  58.         $this->displayedOn = clone $this->displayedOn;
  59.     }
  60.     public function getUniqueId(): string
  61.     {
  62.         if (null !== $this->uniqueId) {
  63.             return $this->uniqueId;
  64.         }
  65.         return $this->uniqueId = new Ulid();
  66.     }
  67.     public function isFormDecorationField(): bool
  68.     {
  69.         return null !== u($this->getCssClass())->indexOf('field-form_panel');
  70.     }
  71.     public function getFieldFqcn(): string
  72.     {
  73.         return $this->fieldFqcn;
  74.     }
  75.     /**
  76.      * @internal Don't use this method yourself. EasyAdmin uses it internally
  77.      *           to set the field FQCN. It's OK to use getFieldFqcn() to get this value.
  78.      */
  79.     public function setFieldFqcn(string $fieldFqcn): void
  80.     {
  81.         $this->fieldFqcn $fieldFqcn;
  82.     }
  83.     public function getProperty(): string
  84.     {
  85.         return $this->propertyName;
  86.     }
  87.     public function setProperty(string $propertyName): void
  88.     {
  89.         $this->propertyName $propertyName;
  90.     }
  91.     /**
  92.      * Returns the original unmodified value stored in the entity field.
  93.      */
  94.     public function getValue()
  95.     {
  96.         return $this->value;
  97.     }
  98.     public function setValue($value): void
  99.     {
  100.         $this->value $value;
  101.     }
  102.     /**
  103.      * Returns the value to be displayed for the field (it could be the
  104.      * same as the value stored in the field or not).
  105.      */
  106.     public function getFormattedValue()
  107.     {
  108.         return $this->formattedValue;
  109.     }
  110.     public function setFormattedValue($formattedValue): void
  111.     {
  112.         $this->formattedValue $formattedValue;
  113.     }
  114.     public function getFormatValueCallable(): ?callable
  115.     {
  116.         return $this->formatValueCallable;
  117.     }
  118.     public function setFormatValueCallable(?callable $callable): void
  119.     {
  120.         $this->formatValueCallable $callable;
  121.     }
  122.     public function getLabel(): ?string
  123.     {
  124.         return $this->label;
  125.     }
  126.     public function setLabel(?string $label): void
  127.     {
  128.         $this->label $label;
  129.     }
  130.     public function getFormType(): ?string
  131.     {
  132.         return $this->formType;
  133.     }
  134.     public function setFormType(string $formTypeFqcn): void
  135.     {
  136.         $this->formType $formTypeFqcn;
  137.     }
  138.     public function getFormTypeOptions(): array
  139.     {
  140.         return $this->formTypeOptions->all();
  141.     }
  142.     public function getFormTypeOption(string $optionName)
  143.     {
  144.         return $this->formTypeOptions->get($optionName);
  145.     }
  146.     public function setFormTypeOptions(array $formTypeOptions): void
  147.     {
  148.         $this->formTypeOptions KeyValueStore::new($formTypeOptions);
  149.     }
  150.     /**
  151.      * @param string $optionName You can use "dot" notation to set nested options (e.g. 'attr.class')
  152.      */
  153.     public function setFormTypeOption(string $optionName$optionValue): void
  154.     {
  155.         $this->formTypeOptions->set($optionName$optionValue);
  156.     }
  157.     /**
  158.      * @param string $optionName You can use "dot" notation to set nested options (e.g. 'attr.class')
  159.      */
  160.     public function setFormTypeOptionIfNotSet(string $optionName$optionValue): void
  161.     {
  162.         $this->formTypeOptions->setIfNotSet($optionName$optionValue);
  163.     }
  164.     public function isSortable(): ?bool
  165.     {
  166.         return $this->sortable;
  167.     }
  168.     public function setSortable(bool $isSortable): void
  169.     {
  170.         $this->sortable $isSortable;
  171.     }
  172.     public function isVirtual(): ?bool
  173.     {
  174.         return $this->virtual;
  175.     }
  176.     public function setVirtual(bool $isVirtual): void
  177.     {
  178.         $this->virtual $isVirtual;
  179.     }
  180.     public function getTextAlign(): ?string
  181.     {
  182.         return $this->textAlign;
  183.     }
  184.     public function setTextAlign(string $textAlign): void
  185.     {
  186.         $this->textAlign $textAlign;
  187.     }
  188.     public function getPermission(): ?string
  189.     {
  190.         return $this->permission;
  191.     }
  192.     public function setPermission(string $permission): void
  193.     {
  194.         $this->permission $permission;
  195.     }
  196.     public function getHelp(): ?string
  197.     {
  198.         return $this->help;
  199.     }
  200.     public function setHelp(string $help): void
  201.     {
  202.         $this->help $help;
  203.     }
  204.     public function getCssClass(): string
  205.     {
  206.         return $this->cssClass;
  207.     }
  208.     public function setCssClass(string $cssClass): void
  209.     {
  210.         $this->cssClass trim($cssClass);
  211.     }
  212.     public function getTranslationParameters(): array
  213.     {
  214.         return $this->translationParameters;
  215.     }
  216.     public function setTranslationParameters(array $translationParameters): void
  217.     {
  218.         $this->translationParameters $translationParameters;
  219.     }
  220.     public function getTemplateName(): ?string
  221.     {
  222.         return $this->templateName;
  223.     }
  224.     public function setTemplateName(?string $templateName): void
  225.     {
  226.         $this->templateName $templateName;
  227.     }
  228.     public function getTemplatePath(): ?string
  229.     {
  230.         return $this->templatePath;
  231.     }
  232.     public function setTemplatePath(?string $templatePath): void
  233.     {
  234.         $this->templatePath $templatePath;
  235.     }
  236.     public function getAssets(): AssetsDto
  237.     {
  238.         return $this->assets;
  239.     }
  240.     public function setAssets(AssetsDto $assets): void
  241.     {
  242.         $this->assets $assets;
  243.     }
  244.     public function addCssFile(string $cssFilePath): void
  245.     {
  246.         $this->assets->addCssFile($cssFilePath);
  247.     }
  248.     public function addJsFile(string $jsFilePath): void
  249.     {
  250.         $this->assets->addJsFile($jsFilePath);
  251.     }
  252.     public function addHtmlContentToHead(string $htmlContent): void
  253.     {
  254.         $this->assets->addHtmlContentToHead($htmlContent);
  255.     }
  256.     public function addHtmlContentToBody(string $htmlContent): void
  257.     {
  258.         $this->assets->addHtmlContentToBody($htmlContent);
  259.     }
  260.     public function getCustomOptions(): KeyValueStore
  261.     {
  262.         return $this->customOptions;
  263.     }
  264.     public function getCustomOption(string $optionName)
  265.     {
  266.         return $this->customOptions->get($optionName);
  267.     }
  268.     public function setCustomOptions(array $customOptions): void
  269.     {
  270.         $this->customOptions KeyValueStore::new($customOptions);
  271.     }
  272.     public function setCustomOption(string $optionName$optionValue): void
  273.     {
  274.         $this->customOptions->set($optionName$optionValue);
  275.     }
  276.     public function getDoctrineMetadata(): KeyValueStore
  277.     {
  278.         return $this->doctrineMetadata;
  279.     }
  280.     public function setDoctrineMetadata(array $metadata): void
  281.     {
  282.         $this->doctrineMetadata KeyValueStore::new($metadata);
  283.     }
  284.     public function getDisplayedOn(): KeyValueStore
  285.     {
  286.         return $this->displayedOn;
  287.     }
  288.     public function setDisplayedOn(KeyValueStore $displayedOn): void
  289.     {
  290.         $this->displayedOn $displayedOn;
  291.     }
  292.     public function isDisplayedOn(string $pageName): bool
  293.     {
  294.         return $this->displayedOn->has($pageName);
  295.     }
  296. }