File: D:/HostingSpaces/Neopoints/momsecurity.be/app/Komma/Kms/Core/Attributes/ComponentArea.php
<?php
namespace App\Komma\Kms\Core\Attributes;
use App\Komma\Dynamic\ComponentArea\ComponentAreaInterface;
use App\Komma\Dynamic\Component\ComponentAttributeKey;
use App\Komma\Dynamic\ComponentArea\ComponentAreaService;
use App\Komma\Dynamic\ComponentType\ComponentType;
use App\Komma\Dynamic\ComponentType\ComponentTypeInterface;
use App\Komma\Dynamic\ComponentType\ComponentTypeResolver;
use App\Komma\Kms\Core\Attributes\Models\Traits\HasSubFoldersInterface;
use App\Komma\Kms\Core\Attributes\Models\Traits\SubFolderTrait;
use FontLib\TrueType\Collection;
use Illuminate\Support\MessageBag;
use Illuminate\View\View;
/**
* Class DynamicGroupTypes
*
*
* @package App\Komma\Kms\Core\Attributes
*/
class ComponentArea extends Attribute implements ComponentAreaInterface
{
use SubFolderTrait;
/** @var string[] */
private $componentTypes = [];
/** @var Collection $components */
private $components;
/**
* DynamicGroupTypes constructor.
*/
public function __construct()
{
$this->subFolder = '';
$this->components = collect();
$this->componentTypes = [];
parent::__construct();
}
/**
* Returns a view that visually represents this attribute
*/
public function render(): View
{
$data = [
'attribute' => $this,
'components' => $this->components ?: collect(),
'allComponentTypes' => ComponentTypeResolver::resolveAll() ?: collect(),
'componentAttributeFieldsRegex' => ComponentAttributeKey::getRegexForAttributeKeysInsideComponentWithKey((string) $this->getKey(), $this->getAssociatedLanguage()->iso_2),
'errors' => new MessageBag(), //Needed for unit testing
];
return view('kms.attributes.componentArea', $data);
}
/**
* @return string The value associated with the attribute
*/
public function getValue(): string
{
//Convert internal value to json for storing in the database only.
return $this->value;
}
/**
* @param string $value The value associated with the attribute
* @return $this
*/
public function setValue(string $value)
{
//VALUE CAN BE JSON DATA FROM DATABASE. OR FROM INPUT. IF IT IS FROM INPUT, THEN IT COMES FROM A DYNAMICALLY UPDATED HIDDEN INPUT
$this->value = $value;
return $this;
}
/**
* Returns an array with names of component types
*
* @return string[]
*/
public function getComponentTypes(): array
{
return $this->componentTypes;
}
/**
* Set the allowed component types for the component area.
*
*
* @param string[] $componentTypes
* @return ComponentArea
*/
public function setComponentTypes(array $componentTypes): ComponentArea
{
$this->componentTypes = array_map(function($item) { //Only allow string values
if(!is_string($item)) throw new \InvalidArgumentException('The componentTypes array must only contain strings that represent the names of the available componentTypes.');
return $item;
}, $componentTypes);
return $this;
}
}