File: D:/HostingSpaces/carrotps/carrotps.com/app/Komma/Components/ComponentType/Types/Downloads.php
<?php
namespace App\Komma\Components\ComponentType\Types;
use App\Komma\Buttons\Kms\ButtonService;
use App\Komma\Buttons\Models\Button;
use App\Komma\Components\Component\ViewComponent;
use App\Komma\Kms\Core\Attributes\MultiSelect;
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\Seperator;
use App\Komma\Kms\Core\Attributes\TextArea;
use App\Komma\Kms\Core\Attributes\TextField;
use App\Komma\Kms\Core\Attributes\Title;
use App\Komma\Servicepoints\Kms\ServicepointService;
use App\Komma\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('Titel'))
->mapValueFrom(Attribute::ValueFromComponent, 'download_title')
);
$this->attributes->push(new Title('Downloads'));
$this->attributes->push((new Documents())
->setSubFolder('component_downloads')
->setMaxDocuments(40)
->mapValueFrom(Attribute::ValueFromComponent, 'downloads') //Needed to sustain Attribute integrity.
);
$this->attributes->push(new Seperator());
$this->attributes->push(new Title('Contactpersoon'));
$this->attributes->push((new TextField('Titel'))
->mapValueFrom(Attribute::ValueFromComponent, 'personal_header')
);
$this->attributes->push((new MultiSelect())
->setLabelText('Contactpersoon')
->setItems($selectServicepointOptions->toArray())
->setMaxItemsToSelect(1)
->canBeLinkedWith(Servicepoint::class)
->mapValueFrom(Attribute::ValueFromComponent, 'servicepoints')
);
$this->attributes->push(new Seperator());
$this->attributes->push(new Title('Opties'));
$this->attributes->push((new OnOff())
->setLabelText("Omwisselen Download/Contactpersoon")
->mapValueFrom(Attribute::ValueFromComponent, 'reversed')
);
}
public function prepare(ViewComponent $viewComponent)
{
$viewComponent->downloads = $viewComponent->downloads->sortBy('sort_order');
return $viewComponent;
}
}