File: D:/HostingSpaces/SBogers10/inzigd.komma.pro/app/Komma/Components/ComponentType/Types/Triptych.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\Documents;
use App\Komma\Kms\Core\Attributes\Models\ImageProperty;
use App\Komma\Kms\Core\Attributes\OnOff;
use App\Komma\Kms\Core\Attributes\TextArea;
class Triptych extends AbstractComponentType
{
public function __construct()
{
//Set an id that corresponds to the ComponentTypes enum
$this->id = ComponentTypes::TRIPTYCH;
//Set icon and name
$this->name = 'triptych';
parent::__construct();
$this->attributes->push((new TextArea())
->enableTinymceEditor()
->setLabelText('text')
->setPlaceholderText('Ex. Lorum ipsum')
->setDataAttribute('tab', 'Links')
->mapValueFrom(Attribute::ValueFromComponent, 'left_description')
);
$this->addButton('left_button', 'Links', 'Button');
$this->attributes->push((new Documents())
->setLabelText('Afbeelding Verticaal')
->onlyAllowImages()
->setSubFolder('component_uploads')
->setMaxDocuments(1)
->setImageProperties([
(new ImageProperty())->setName('large')->setCropMethod(ImageProperty::Resize)->setWidth(540),
])
->setSmallDragAndDropArea()
->mapValueFrom(Attribute::ValueFromComponent, 'image_vertical') //Needed to sustain Attribute integrity.
);
$this->attributes->push((new Documents())
->setLabelText('Afbeelding Horizontal')
->onlyAllowImages()
->setSubFolder('component_uploads')
->setMaxDocuments(1)
->setImageProperties([
(new ImageProperty())->setName('large')->setCropMethod(ImageProperty::Resize)->setWidth(800),
])
->setSmallDragAndDropArea()
->mapValueFrom(Attribute::ValueFromComponent, 'image_horizontal') //Needed to sustain Attribute integrity.
);
$this->attributes->push((new TextArea())
->enableTinymceEditor()
->setLabelText('text')
->setPlaceholderText('Ex. Lorum ipsum')
->setDataAttribute('tab', 'Rechts')
->mapValueFrom(Attribute::ValueFromComponent, 'right_description')
);
$this->addButton('right_button', 'Rechts', 'Carla');
}
public function prepare(ViewComponent $viewComponent)
{
foreach(['left', 'right'] as $key) {
$viewComponent->{$key} = (object)[
'description' => $viewComponent->{$key . '_description'},
'button' => (object)[
'label' => $viewComponent->{$key . '_button_label'},
'link' => $viewComponent->{$key . '_button_link'},
]
];
unset($viewComponent->{$key . '_description'});
unset($viewComponent->{$key . '_button_label'});
unset($viewComponent->{$key . '_button_link'});
}
}
}