File: D:/HostingSpaces/slenders/slenders.nl/app/Komma/Components/ComponentType/Types/DoubleImageThird.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\Models\SelectOption;
use App\Komma\Kms\Core\Attributes\Models\SelectOptionInterface;
use App\Komma\Kms\Core\Attributes\MultiSelect;
use App\Komma\Kms\Core\Attributes\OnOff;
use App\Komma\Kms\Core\Attributes\Select;
use App\Komma\Kms\Core\Attributes\TextArea;
use App\Komma\Shop\Products\Product\Product;
use App\Komma\Shop\Products\Product\ProductService;
class DoubleImageThird extends AbstractComponentType
{
//Set an id that corresponds to the ComponentTypes enum
protected $id = ComponentTypes::DOUBLE_IMAGE_THIRD;
//Set icon and name
protected $name = 'double-image-third';
public function __construct()
{
parent::__construct();
$this->attributes->push((new Documents())
->setLabelText('Groot')
->onlyAllowImages()
->setSubFolder('component_uploads')
->setMaxDocuments(1)
->setImageProperties([
(new ImageProperty())->setName('large')->setCropMethod(ImageProperty::Resize)->setWidth(1000),
(new ImageProperty())->setName('medium')->setCropMethod(ImageProperty::Resize)->setWidth(700),
(new ImageProperty())->setName('small')->setCropMethod(ImageProperty::Resize)->setWidth(375),
])
->setSmallDragAndDropArea()
->mapValueFrom(Attribute::ValueFromComponent, 'large') //Needed to sustain Attribute integrity.
);
$this->attributes->push((new Documents())
->setLabelText('Klein')
->onlyAllowImages()
->setSubFolder('component_uploads')
->setMaxDocuments(1)
->setImageProperties([
(new ImageProperty())->setName('large')->setCropMethod(ImageProperty::Resize)->setWidth(700),
(new ImageProperty())->setName('medium')->setCropMethod(ImageProperty::Resize)->setWidth(450),
(new ImageProperty())->setName('small')->setCropMethod(ImageProperty::Resize)->setWidth(375),
])
->setSmallDragAndDropArea()
->setExplanation('<strong>Let op!</strong> Niet zichtbaar op mobiel')
->mapValueFrom(Attribute::ValueFromComponent, 'small') //Needed to sustain Attribute integrity.
);
$stylingOptions = collect();
$stylingOptions->push((app(SelectOptionInterface::class))
->setContent('Geen')
->setHtmlContent('Geen')
->setValue(0));
$stylingOptions->push((app(SelectOptionInterface::class))
->setContent('Top bar')
->setHtmlContent('Top bar')
->setValue(1));
$stylingOptions->push((app(SelectOptionInterface::class))
->setContent('Side bars')
->setHtmlContent('Side bars')
->setValue(2));
$this->attributes->push((new Select())
->setLabelText('Styling')
->setItems($stylingOptions->toArray())
->mapValueFrom(Attribute::ValueFromComponent, 'styling')
);
$this->attributes->push((new OnOff())
->setLabelText("Spiegelen")
->mapValueFrom(Attribute::ValueFromComponent, 'reversed')
);
}
public function prepare(ViewComponent $viewComponent) {
foreach (['large', 'small'] as $size) {
if(isset($viewComponent->{$size}) && $viewComponent->{$size}->isNotEmpty()){
$viewComponent->{$size} = $viewComponent->{$size}->first();
}
else $viewComponent->{$size} = null;
}
}
}