HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers68/otium-gebiedsontwikkeling.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');
    }
}