File: D:/HostingSpaces/slenders/slenders.nl/app/Komma/Components/ComponentType/Types/DoubleImage.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\MultiSelect;
use App\Komma\Kms\Core\Attributes\OnOff;
use App\Komma\Kms\Core\Attributes\TextArea;
use App\Komma\Shop\Products\Product\Product;
use App\Komma\Shop\Products\Product\ProductService;
class DoubleImage extends AbstractComponentType
{
//Set an id that corresponds to the ComponentTypes enum
protected $id = ComponentTypes::DOUBLE_IMAGE;
//Set icon and name
protected $name = 'double-image';
public function __construct()
{
parent::__construct();
$this->attributes->push((new Documents())
->setLabelText('Afbeelding')
->onlyAllowImages()
->setSubFolder('component_uploads')
->setMaxDocuments(1)
->setImageProperties([
(new ImageProperty())->setName('large')->setCropMethod(ImageProperty::Resize)->setWidth(900),
(new ImageProperty())->setName('medium')->setCropMethod(ImageProperty::Resize)->setWidth(600),
(new ImageProperty())->setName('small')->setCropMethod(ImageProperty::Resize)->setWidth(375),
])
->setSmallDragAndDropArea()
->mapValueFrom(Attribute::ValueFromComponent, 'left') //Needed to sustain Attribute integrity.
);
$this->attributes->push((new Documents())
->setLabelText('Afbeelding')
->onlyAllowImages()
->setSubFolder('component_uploads')
->setMaxDocuments(1)
->setImageProperties([
(new ImageProperty())->setName('large')->setCropMethod(ImageProperty::Resize)->setWidth(900),
(new ImageProperty())->setName('medium')->setCropMethod(ImageProperty::Resize)->setWidth(600),
(new ImageProperty())->setName('small')->setCropMethod(ImageProperty::Resize)->setWidth(375),
])
->setSmallDragAndDropArea()
->mapValueFrom(Attribute::ValueFromComponent, 'right') //Needed to sustain Attribute integrity.
);
}
public function prepare(ViewComponent $viewComponent) {
foreach (['left', 'right'] as $size) {
if(isset($viewComponent->{$size}) && $viewComponent->{$size}->isNotEmpty()){
$viewComponent->{$size} = $viewComponent->{$size}->first();
}
else $viewComponent->{$size} = null;
}
}
}