File: D:/HostingSpaces/blijegasten/blijegasten.be/app/Komma/Components/ComponentType/Types/Steps.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\TextArea;
use App\Komma\Kms\Core\Attributes\TextField;
class Steps extends AbstractComponentType
{
const POSSIBLE_AMOUNT = 4;
public function __construct()
{
//Set an id that corresponds to the ComponentTypes enum
$this->id = ComponentTypes::STEPS;
//Set icon and name
$this->name = 'steps';
parent::__construct();
for($i = 0; $i < self::POSSIBLE_AMOUNT; $i++) {
$this->attributes->push((new TextField('Boventitel'))
->mapValueFrom(Attribute::ValueFromItself, 'subtitle_' . ($i + 1))//Needed to sustain Attribute integrity.
->setPlaceholderText('Ex. Ontzorgen')
->setDataAttribute('tab', ($i + 1))
);
$this->attributes->push((new TextField('Titel'))
->mapValueFrom(Attribute::ValueFromItself, 'title_' . ($i + 1))//Needed to sustain Attribute integrity.
->setPlaceholderText('Ex. Geen omkijken naar administratie')
->setDataAttribute('tab', ($i + 1))
);
$this->attributes->push((new TextArea())
->setLabelText('Description')
->setPlaceholderText('Ex. Lorum ipsum')
->mapValueFrom(Attribute::ValueFromItself, 'description_' . ($i + 1))//Needed to sustain Attribute integrity.
->setDataAttribute('tab', ($i + 1)));
}
}
public function prepare(ViewComponent $viewComponent)
{
$steps = collect();
for($i = 1; $i <= self::POSSIBLE_AMOUNT; $i++) {
$subtitle = $viewComponent->{'subtitle_'.$i};
$title = $viewComponent->{'title_'.$i};
$description = $viewComponent->{'description_'.$i};
if(!empty($title) || !empty($description)) {
$step = (object)[
'id' => $i,
'subtitle' => $subtitle,
'title' => $title,
'description' => $description
];
$steps->push($step);
}
unset($viewComponent->{'subtitle_'.$i});
unset($viewComponent->{'title_'.$i});
unset($viewComponent->{'description_'.$i});
}
$viewComponent->steps = $steps;
}
}