File: D:/HostingSpaces/SBogers10/bomacon.komma.pro/app/Components/ComponentType/Types/Downloads.php
<?php
namespace App\Components\ComponentType\Types;
use App\Buttons\Kms\ButtonService;
use App\Buttons\Models\Button;
use App\Components\Component\ViewComponent;
use Komma\KMS\Core\Attributes\MultiSelect;
use App\Components\ComponentType\ComponentTypes;
use Komma\KMS\Core\Attributes\Attribute;
use Komma\KMS\Core\Attributes\Documents;
use Komma\KMS\Core\Attributes\Models\ImageProperty;
use Komma\KMS\Core\Attributes\OnOff;
use Komma\KMS\Core\Attributes\Seperator;
use Komma\KMS\Core\Attributes\TextArea;
use Komma\KMS\Core\Attributes\TextField;
use Komma\KMS\Core\Attributes\Title;
use App\Servicepoints\Kms\ServicepointService;
use App\Servicepoints\Models\Servicepoint;
class Downloads extends AbstractComponentType
{
public function __construct()
{
//Set an id that corresponds to the ComponentTypes enum
$this->id = ComponentTypes::DOWNLOADS;
//Set icon and name
$this->name = 'downloads';
parent::__construct();
$servicepointsService = \App::make(ServicepointService::class);
$selectServicepointOptions = $servicepointsService->getOptionsForSelect(false, true);
$this->attributes->push((new TextField(__('kms/attributes/components.title')))
->mapValueFrom(Attribute::ValueFromComponent, 'download_title')
);
$this->attributes->push(new Title('Downloads'));
$this->attributes->push((new Documents())
->setSubFolder('component_downloads')
->setMaxDocuments(12)
->mapValueFrom(Attribute::ValueFromComponent, 'downloads') //Needed to sustain Attribute integrity.
);
$this->attributes->push(new Seperator());
$this->attributes->push(new Title(__('kms/attributes/components.contact_person')));
$this->attributes->push((new TextField('Titel'))
->mapValueFrom(Attribute::ValueFromComponent, 'personal_header')
);
$this->attributes->push((new MultiSelect())
->setLabelText(__('kms/attributes/components.contact_person'))
->setItems($selectServicepointOptions->toArray())
->setMaxItemsToSelect(1)
->canBeLinkedWith(Servicepoint::class)
->mapValueFrom(Attribute::ValueFromComponent, 'servicepoints')
);
$this->attributes->push(new Seperator());
$this->attributes->push(new Title(__('kms/attributes/components.options')));
$this->attributes->push((new OnOff())
->setLabelText(__('kms/attributes/components.swap_download_contactperson'))
->mapValueFrom(Attribute::ValueFromComponent, 'reversed')
);
}
public function prepare(ViewComponent $viewComponent)
{
$viewComponent->downloads = $viewComponent->downloads->sortBy('sort_order');
return $viewComponent;
}
}