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/shop.komma.nl/app/Categories/Kms/CategorySection.php
<?php


namespace App\Categories\Kms;

use App\Properties\Kms\PropertyService;
use Komma\KMS\Components\ComponentType\ComponentTypes;
use Komma\KMS\Core\Attributes\Attribute;
use Komma\KMS\Core\Attributes\ComponentArea;
use Komma\KMS\Core\Attributes\Documents;
use Komma\KMS\Core\Attributes\MultiSelect;
use Komma\KMS\Core\Sections\Section;
use Komma\KMS\Core\Attributes\Models\ImageProperty;
use Komma\KMS\Core\Attributes\OnOff;
use Komma\KMS\Core\Attributes\Select;
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 Komma\KMS\Users\Models\KmsUserRole;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;

class CategorySection extends Section
{
    protected string $slug = "categories";

    private CategoryModelService $categoryService;

    /**
     * PageSection constructor.
     * @param $slug
     */
    function __construct($slug)
    {
        $this->categoryService = new CategoryModelService();
        parent::__construct($slug);
    }

    /**
     * Generates the attributes for this section. They all must extend the App\Kms\Core\Attributes\Attribute class
     * This is the place where you need to setup your sections appearance. Just make sure you build an array of attributes
     * and put each attribute in a AbstractSectionTabItem with a SectionTabGroups constant to link them to a tab.
     *
     * @param  Model  $currentModel
     * @return Collection A collection of SectionTabItems
     * @see PageRepository::saveModel()
     */
    public function defineAttributesAndTabs(Model $currentModel = null): void
    {
        $categoryOptionModels = $this->categoryService->getOptionsForSelectAsTree();
        $propertyService = new PropertyService();
        $propertyKeys = $propertyService->getPropertyKeyOptionsForSelect();

        $this->tabs->makeTab()->addItems([
            (new Title())
                ->setLabelText(__('KMS::categories.category')),


            (new TextField())
                ->setLabelText(__('KMS::global.codeName'))
                ->setMinimumUserRole(KmsUserRole::SuperAdmin)
                ->setReadOnly(false)
                ->setReference('code_name'),

            (new OnOff())
                ->setLabelText(__('KMS::global.active'))
//            ->switchOn()
                ->setReference('active'),

            (new Select())
                ->setItems($categoryOptionModels->toArray())
                ->setLabelText(__('KMS::categories.parent_category'))
                ->enableExcludeCurrentModelItem()
                ->mapValueFrom(Attribute::ValueFromItself, 'parent_id'),

            (new Documents())
                ->setImageProperties([
                    (new ImageProperty())->setName('thumb')->setCropMethod(ImageProperty::ResizeOnCanvas)->setWidth(100)->setHeight(100),
                    (new ImageProperty())->setName('small')->setCropMethod(ImageProperty::ResizeOnCanvas)->setWidth(240)->setHeight(240),
                    (new ImageProperty())->setName('medium')->setCropMethod(ImageProperty::ResizeOnCanvas)->setWidth(460)->setHeight(460),
                    (new ImageProperty())->setName('large')->setCropMethod(ImageProperty::ResizeOnCanvas)->setWidth(500)->setHeight(500),
                ])
                ->onlyAllowImages()
                ->setLabelText(__('KMS::global.images'))
                ->setMaxDocuments(5)
                ->setSubFolder('pages')
                ->mapValueFrom(Attribute::ValueFromDocuments, 'documents'),

            (new MultiSelect())
                ->setItems($propertyKeys->toArray())
                ->setLabelText(__('KMS::categories.required_attributes'))
                ->mapValueFrom(Attribute::ValueFromModelHasManyRelation, 'requiredPropertyKeys|id'),
        ]);

        $languageAttributes = [];
        if ($currentModel) {
            $languageAttributes[] = (new TextField())
                ->setLabelText(__('KMS::global.updated_at'))
                ->setReadOnly(true)
                ->setStyleClass('hidden')
                ->setReference('updated_at');
        }

        $languageAttributes[] = (new Title())
            ->setLabelText(__('KMS::global.information'));

        $languageAttributes[] = (new TextField())
            ->setLabelText(__('KMS::global.title'))
            ->setPlaceholderText(__('KMS::global.enterTitle'))
            ->setRules('required')
            ->setReference('name');

        $languageAttributes[] = (new Seperator());

        $languageAttributes[] = (new TextField())
            ->setLabelText(__('KMS::global.metaTitle'))
            ->setPlaceholderText(__('KMS::global.enterTitle'))
            ->setReference('meta_title');

        $languageAttributes[] = (new TextArea())
            ->setLabelText(__('KMS::global.metaDescription'))
            ->setPlaceholderText(__('KMS::global.enterMetaDescription'))
            ->setReference('meta_description');

        $languageAttributes[] = (new ComponentArea())
            ->setComponentTypes([
                ComponentTypes::TEXT,
            ])
            ->setSubFolder('category_component_data')
            ->mapValueFrom(Attribute::ValueFromComponentArea, 'category_components');

        $this->tabs->makeLanguageTabTemplate()->addItems($languageAttributes);
    }
}