File: D:/HostingSpaces/SBogers95/rentman.io/app/Komma/Dynamic/ComponentType/Types/Cards.php
<?php
namespace App\Komma\Dynamic\ComponentType\Types;
use App\Komma\Dynamic\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\Select;
use App\Komma\Kms\Core\Attributes\Seperator;
use App\Komma\Kms\Core\Attributes\TextArea;
use App\Komma\Kms\Core\Attributes\TextField;
class Cards extends AbstractComponentType
{
//Set an id that corresponds to the ComponentTypes enum
protected $id = ComponentTypes::CARDS;
//Set icon and name
protected $name = 'cards';
public function __construct()
{
parent::__construct();
$this->attributes->push((new OnOff())
->setLabelText('Grey Background')
->setStyleClass('is-background-option')
->mapValueFrom(Attribute::ValueFromItself, 'grey_background'));
$this->attributes->push((new OnOff())
->setLabelText('Boxed')
->mapValueFrom(Attribute::ValueFromItself, 'boxed'));
$this->attributes->push((new OnOff())
->setLabelText('Webinar grid?')
->mapValueFrom(Attribute::ValueFromItself, 'webinar'));
$this->attributes->push((new TextField('Row heading'))
->mapValueFrom(Attribute::ValueFromItself, 'row_heading')//Needed to sustain Attribute integrity.
->setPlaceholderText('ex. title')
);
$this->attributes->push((new OnOff())
->setLabelText('Use hover style layout')
->mapValueFrom(Attribute::ValueFromItself, 'hover_layout'));
for ($i = 0; $i < 6; $i++) {
$this->translatableAttributes[] = 'title_'.($i + 1);
$this->translatableAttributes[] = 'description_'.($i + 1);
$this->translatableAttributes[] = 'button_'.($i + 1).'_label';
// $this->translatableAttributes[] = 'button_' . ($i + 1) . '.2_label';
$this->attributes->push((new Select())
->setItems($this->getIconOptions())
->setLabelText('Icon')
->mapValueFrom(Attribute::ValueFromItself, 'icon_'.($i + 1))
->setDataAttribute('tab', ($i + 1))
);
$this->attributes->push((new Documents())
->setLabelText('Image')
->onlyAllowImages()
->setSubFolder('component_uploads')
->setMaxDocuments(1)
->setDataAttribute('tab', ($i + 1))
->setImageProperties([
(new ImageProperty())->setName('original')->setCropMethod(ImageProperty::Resize)->setWidth(1200),
(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::ValueFromItself, 'image_'.($i + 1)) //Needed to sustain Attribute integrity.
);
$this->attributes->push((new TextField('Title'))
->mapValueFrom(Attribute::ValueFromItself, 'title_'.($i + 1))//Needed to sustain Attribute integrity.
->setPlaceholderText('Ex. Improve team collaberation')
->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)));
// $this->attributes->push((new Seperator())
// ->setDataAttribute('tab', ($i + 1)));
$this->addButton('Button '.($i + 1), ($i + 1));
// $this->addButton('Button ' . ($i + 1) . '.2' , ($i + 1)); // Can't do this, buggy dynamic components logic
}
}
}