<?php declare(strict_types=1);
namespace MoorlFormBuilder\Core\Content\FormElement;
use Shopware\Core\Framework\DataAbstractionLayer\Entity;
class FormElement extends Entity implements FormElementInterface
{
protected string $type;
protected string $mediaType = 'documents';
protected ?string $name = null;
protected $value = null;
protected array $behaviour = [];
protected array $conditions = [];
protected ?bool $useImageSelection = false;
protected ?bool $useCustomTemplate = false;
protected string $gridSizeLg = "12";
public function __construct(array $formElement) {
foreach ($formElement as $k => $v) {
$this->$k = $v;
}
}
/**
* @return null
*/
public function getValue()
{
return $this->value;
}
/**
* @param $value
*/
public function setValue($value = null): void
{
$this->value = $value;
}
/**
* @return string|null
*/
public function getName(): ?string
{
return $this->name;
}
/**
* @return string
*/
public function getMediaType(): string
{
return $this->mediaType ?: 'documents';
}
/**
* @return string
*/
public function getType(): string
{
return $this->type;
}
/**
* @return array
*/
public function getBehaviour(): array
{
return $this->behaviour;
}
/**
* @param array $behaviour
*/
public function setBehaviour(array $behaviour): void
{
$this->behaviour = $behaviour;
}
/**
* @return array
*/
public function getConditions(): array
{
return $this->conditions;
}
/**
* @param array $conditions
*/
public function setConditions(array $conditions): void
{
$this->conditions = $conditions;
}
/**
* @return bool|null
*/
public function getUseImageSelection(): ?bool
{
return $this->useImageSelection;
}
/**
* @param bool|null $useImageSelection
*/
public function setUseImageSelection(?bool $useImageSelection): void
{
$this->useImageSelection = $useImageSelection;
}
/**
* @return bool|null
*/
public function getUseCustomTemplate(): ?bool
{
return $this->useCustomTemplate;
}
/**
* @param bool|null $useCustomTemplate
*/
public function setUseCustomTemplate(?bool $useCustomTemplate): void
{
$this->useCustomTemplate = $useCustomTemplate;
}
public function getBehaviourClass(): string
{
if (empty($this->behaviour)) {
return sprintf("col col-lg-%s", $this->gridSizeLg);
}
$txt = "";
foreach ($this->behaviour as $breakpoint => $behaviour) {
if (isset($behaviour['order']) && (int)$behaviour['order'] !== 0) {
$txt .= sprintf("order-%s-%d ", $breakpoint, $behaviour['order']);
}
if (isset($behaviour['width']) && (int)$behaviour['width'] !== -1) {
$txt .= sprintf("col-%s-%d ", $breakpoint, $behaviour['width']);
} else {
continue;
}
if (isset($behaviour['visible']) && empty($this->conditions)) {
$txt .= sprintf("d-%s-%s ", $breakpoint, $behaviour['visible'] ? 'block' : 'none');
}
}
return trim(str_replace(["base-","-0"], "", $txt));
}
public function getImageClass(): string
{
if ($this->useImageSelection && !$this->useCustomTemplate) {
return "moorl-form-builder-image-selection";
}
return "";
}
}