File: D:/HostingSpaces/SBogers10/inzigd.komma.pro/app/Komma/Components/ComponentType/Types/Usp.php
<?php
namespace App\Komma\Components\ComponentType\Types;
use App\Komma\Components\Component\ViewComponent;
use App\Komma\Components\ComponentType\ComponentTypes;
use App\Komma\Kms\Core\Attributes\Attribute;
use App\Komma\Kms\Core\Attributes\OnOff;
use App\Komma\Kms\Core\Attributes\TextArea;
use App\Komma\Kms\Core\Attributes\TextField;
class Usp extends AbstractComponentType
{
const POSSIBLE_AMOUNT = 6;
public function __construct()
{
//Set an id that corresponds to the ComponentTypes enum
$this->id = ComponentTypes::USP;
//Set icon and name
$this->name = 'usp';
parent::__construct();
$this->attributes->push((new TextField('Titel'))
->setPlaceholderText('Ex. Waarom de workshops van Inzight?')
->mapValueFrom(Attribute::ValueFromComponent, 'title')
);
for($i = 1; $i <= self::POSSIBLE_AMOUNT; $i++) {
$this->attributes->push((new TextField('Usp'))
->setPlaceholderText('Ex. Meer aandacht')
->setDataAttribute('tab', $i)
->mapValueFrom(Attribute::ValueFromComponent, 'title_' . $i)//Needed to sustain Attribute integrity.
);
$this->attributes->push((new TextArea())
->setLabelText('Omschrijving')
->setPlaceholderText('Ex. Aangezien echte aandacht daar voor mij...')
->setDataAttribute('tab', $i)
->mapValueFrom(Attribute::ValueFromComponent, 'description_' . $i)//Needed to sustain Attribute integrity.
);
}
}
public function prepare(ViewComponent $viewComponent)
{
$cards = collect();
for($i = 1; $i <= self::POSSIBLE_AMOUNT; $i++) {
$title = $viewComponent->{'title_'.$i};
$description = $viewComponent->{'description_'.$i};
if(!empty($title) || !empty($description)) {
$card = (object)[
'id' => $i,
'title' => $title,
'description' => $description
];
$cards->push($card);
}
unset($viewComponent->{'title_'.$i});
unset($viewComponent->{'description_'.$i});
}
$viewComponent->cards = $cards;
}
}