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/SBogers10/base.komma.pro/app/Components/Types/Testimonials.php
<?php


namespace App\Components\Types;

use App\Buttons\Kms\ButtonService;
use App\Buttons\Models\Button;
use App\Components\ComponentTypes;
use App\Testimonials\Models\Testimonial;
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 Testimonials extends AbstractComponentType
{

    protected int $id = ComponentTypes::TESTIMONIALS;
    protected string $name = 'testimonials';

    public function defineAttributesAndTabs()
    {
        $testimonialService = new ModelService();
        $testimonialService->setModelClassName(Testimonial::class);
        $selectTestimonialOptions = $testimonialService->getOptionsForSelect(false, true);

        $buttonsService = App::make(ButtonService::class);
        $selectButtonOptions = $buttonsService->getOptionsForSelect(false, true);

        $this->addItems([
            (new TextField())
                ->setReference('testimonialsHeader')
                ->setLabelText(__('KMS::attributes/components.title')),

            (new MultiSelect())
                ->setReference('testimonials')
                ->enableSortable()
                ->setLabelText(__('KMS::attributes/components.testimonials'))
                ->setItems($selectTestimonialOptions->toArray())
                ->setMaxItemsToSelect(4)
                ->canBeLinkedWith(Testimonial::class),

            (new MultiSelect())
                ->setReference('testimonialsButtons')
                ->setLabelText(__('KMS::global.button'))
                ->setItems($selectButtonOptions->toArray())
                ->setMaxItemsToSelect(1)
                ->canBeLinkedWith(Button::class)
        ]);
    }

    public function prepare(ViewComponent $viewComponent)
    {
        $viewComponent->testimonials->load('translations', 'documents');
    }
}