custom/plugins/MoorlFormBuilder/src/Core/Content/FormElement/FormElement.php line 19

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace MoorlFormBuilder\Core\Content\FormElement;
  3. use Shopware\Core\Framework\DataAbstractionLayer\Entity;
  4. class FormElement extends Entity implements FormElementInterface
  5. {
  6.     protected string $type;
  7.     protected string $mediaType = 'documents';
  8.     protected ?string $name = null;
  9.     protected $value = null;
  10.     protected array $behaviour = [];
  11.     protected array $conditions = [];
  12.     protected ?bool $useImageSelection = false;
  13.     protected ?bool $useCustomTemplate = false;
  14.     protected string $gridSizeLg = "12";
  15.     public function __construct(array $formElement) {
  16.         foreach ($formElement as $k => $v) {
  17.             $this->$k = $v;
  18.         }
  19.     }
  20.     /**
  21.      * @return null
  22.      */
  23.     public function getValue()
  24.     {
  25.         return $this->value;
  26.     }
  27.     /**
  28.      * @param $value
  29.      */
  30.     public function setValue($value = null): void
  31.     {
  32.         $this->value = $value;
  33.     }
  34.     /**
  35.      * @return string|null
  36.      */
  37.     public function getName(): ?string
  38.     {
  39.         return $this->name;
  40.     }
  41.     /**
  42.      * @return string
  43.      */
  44.     public function getMediaType(): string
  45.     {
  46.         return $this->mediaType ?: 'documents';
  47.     }
  48.     /**
  49.      * @return string
  50.      */
  51.     public function getType(): string
  52.     {
  53.         return $this->type;
  54.     }
  55.     /**
  56.      * @return array
  57.      */
  58.     public function getBehaviour(): array
  59.     {
  60.         return $this->behaviour;
  61.     }
  62.     /**
  63.      * @param array $behaviour
  64.      */
  65.     public function setBehaviour(array $behaviour): void
  66.     {
  67.         $this->behaviour = $behaviour;
  68.     }
  69.     /**
  70.      * @return array
  71.      */
  72.     public function getConditions(): array
  73.     {
  74.         return $this->conditions;
  75.     }
  76.     /**
  77.      * @param array $conditions
  78.      */
  79.     public function setConditions(array $conditions): void
  80.     {
  81.         $this->conditions = $conditions;
  82.     }
  83.     /**
  84.      * @return bool|null
  85.      */
  86.     public function getUseImageSelection(): ?bool
  87.     {
  88.         return $this->useImageSelection;
  89.     }
  90.     /**
  91.      * @param bool|null $useImageSelection
  92.      */
  93.     public function setUseImageSelection(?bool $useImageSelection): void
  94.     {
  95.         $this->useImageSelection = $useImageSelection;
  96.     }
  97.     /**
  98.      * @return bool|null
  99.      */
  100.     public function getUseCustomTemplate(): ?bool
  101.     {
  102.         return $this->useCustomTemplate;
  103.     }
  104.     /**
  105.      * @param bool|null $useCustomTemplate
  106.      */
  107.     public function setUseCustomTemplate(?bool $useCustomTemplate): void
  108.     {
  109.         $this->useCustomTemplate = $useCustomTemplate;
  110.     }
  111.     public function getBehaviourClass(): string
  112.     {
  113.         if (empty($this->behaviour)) {
  114.                 return sprintf("col col-lg-%s", $this->gridSizeLg);
  115.         }
  116.         $txt = "";
  117.         foreach ($this->behaviour as $breakpoint => $behaviour) {
  118.             if (isset($behaviour['order']) && (int)$behaviour['order'] !== 0) {
  119.                 $txt .= sprintf("order-%s-%d ", $breakpoint, $behaviour['order']);
  120.             }
  121.             if (isset($behaviour['width']) && (int)$behaviour['width'] !== -1) {
  122.                 $txt .= sprintf("col-%s-%d ", $breakpoint, $behaviour['width']);
  123.             } else {
  124.                 continue;
  125.             }
  126.             if (isset($behaviour['visible']) && empty($this->conditions)) {
  127.                 $txt .= sprintf("d-%s-%s ", $breakpoint, $behaviour['visible'] ? 'block' : 'none');
  128.             }
  129.         }
  130.         return trim(str_replace(["base-","-0"], "", $txt));
  131.     }
  132.     public function getImageClass(): string
  133.     {
  134.         if ($this->useImageSelection && !$this->useCustomTemplate) {
  135.             return "moorl-form-builder-image-selection";
  136.         }
  137.         return "";
  138.     }
  139. }