File: D:/HostingSpaces/SBogers10/otium.komma.nl/app/Components/Types/FeaturedServices.php
<?php
namespace App\Components\Types;
use App\Buttons\Kms\ButtonService;
use App\Buttons\Models\Button;
use App\Components\ComponentTypes;
use App\Services\Models\Service;
use Illuminate\Support\Facades\App;
use Komma\KMS\Components\Component\ViewComponent;
use Komma\KMS\Components\ComponentType\Types\AbstractComponentType;
use Komma\KMS\Core\Attributes\MultiSelect;
use Komma\KMS\Core\Attributes\TextField;
use Komma\KMS\Core\ModelService;
class FeaturedServices extends AbstractComponentType
{
protected int $id = ComponentTypes::FEATURED_SERVICES;
protected string $name = 'featured-services';
public function defineAttributesAndTabs()
{
$serviceService = new ModelService();
$serviceService->setModelClassName(Service::class);
$selectServiceOptions = $serviceService->getOptionsForSelect(false, true);
$buttonsService = App::make(ButtonService::class);
$selectButtonOptions = $buttonsService->getOptionsForSelect(false, true);
$this->addItems([
(new TextField())
->setReference('featuredServicesHeader')
->setLabelText(__('KMS::attributes/components.title')),
(new MultiSelect())
->setReference('featuredServices')
->enableSortable()
->setLabelText(__('KMS::attributes/components.services'))
->setItems($selectServiceOptions->toArray())
->setMaxItemsToSelect(4)
->canBeLinkedWith(Service::class),
(new MultiSelect())
->setReference('featuredServicesButtons')
->setLabelText(__('KMS::global.button'))
->setItems($selectButtonOptions->toArray())
->setMaxItemsToSelect(1)
->canBeLinkedWith(Button::class),
]);
}
public function prepare(ViewComponent $viewComponent)
{
$viewComponent->featuredServices->load('translations');
}
}