File: D:/HostingSpaces/slenders/slenders.nl/app/Komma/Components/ComponentType/Types/Hero.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;
use App\Komma\Kms\Core\Attributes\TextField;
class Hero extends AbstractComponentType
{
public function __construct()
{
//Set an id that corresponds to the ComponentTypes enum
$this->id = ComponentTypes::HERO;
//Set icon and name
$this->name = 'hero';
parent::__construct();
$this->attributes->push(
(new TextField('Titel'))
->setPlaceholderText('Ex. Over ons')
->mapValueFrom(Attribute::ValueFromComponent, 'name')
);
$this->attributes->push((new Documents())
->setLabelText('image')
->onlyAllowImages()
->setSubFolder('component_uploads')
->setMaxDocuments(1)
->setImageProperties([
(new ImageProperty())->setName('xlarge')->setCropMethod(ImageProperty::Resize)->setWidth(2000),
(new ImageProperty())->setName('large')->setCropMethod(ImageProperty::Resize)->setWidth(1400),
(new ImageProperty())->setName('medium')->setCropMethod(ImageProperty::Resize)->setWidth(800),
(new ImageProperty())->setName('small')->setCropMethod(ImageProperty::Resize)->setWidth(500),
])
->setSmallDragAndDropArea()
->mapValueFrom(Attribute::ValueFromComponent, 'image') //Needed to sustain Attribute integrity.
);
$this->addButton();
}
public function prepare(ViewComponent $viewComponent) {
if(isset($viewComponent->image) && $viewComponent->image->isNotEmpty()){
$viewComponent->image = $viewComponent->image->first();
}
else $viewComponent->image = null;
}
}