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/Pages/Kms/PageSection.php
<?php


namespace App\Pages\Kms;

use App\Components\ComponentTypes;
use Komma\KMS\Core\Attributes\Attribute;
use Komma\KMS\Core\Attributes\ComponentArea;
use Komma\KMS\Core\ModelServiceInterface;
use Komma\KMS\Core\Sections\Section;
use App\Pages\Models\Page;
use Komma\KMS\Core\Attributes\OnOff;
use Komma\KMS\Core\Attributes\Select;
use Komma\KMS\Core\Attributes\TextArea;
use Komma\KMS\Core\Attributes\TextField;
use Illuminate\Database\Eloquent\Model;
use Komma\KMS\Users\Models\KmsUserRole;

final class PageSection extends Section
{
    /**
     * 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.
     *
     * @see PageRepository::saveModel()
     * @param Model $currentModel
     * @return void A collection of SectionTabItems
     */
    public function defineAttributesAndTabs(Model $currentModel = null): void
    {
        /** @var ModelServiceInterface $pageModelService */
        $pageModelService = app(ModelServiceInterface::class);
        $pageModelService->setModelClassName(Page::class);
        $pageOptionModels = $pageModelService->getOptionsForSelectAsTree();


        $this->tabs->makeTab()->addItems([
            (new TextField())
                ->setReference('code_name')
                ->setLabelText(__('KMS::global.codeName'))
                ->setMinimumUserRole(KmsUserRole::SuperAdmin)
                ->setReadOnly(false),

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

            (new OnOff())
                ->setReference('has_wildcard')
                ->setLabelText(__('KMS::global.uses_wildcard'))
                ->setExplanation(__('KMS::pages.wildcard_explanation'))
                ->setMinimumUserRole(KmsUserRole::SuperAdmin)
                ->setRules(['sometimes', 'required', 'integer']),

            (new Select())
                ->setItems($pageOptionModels->toArray())
                ->setLabelText(__('KMS::pages.parent_page'))
                ->enableExcludeCurrentModelItem()
                ->setMinimumUserRole(KmsUserRole::SuperAdmin)
                ->mapValueFrom(Attribute::ValueFromItself, 'parent_id'),
        ]);

        $this->tabs->makeLanguageTabTemplate()->addItems([
            (new TextField())
                ->setReference('name')
                ->setLabelText(__('KMS::global.title')),

            (new TextField())
                ->setReference('meta_title')
                ->setLabelText(__('KMS::global.metaTitle')),

            (new TextArea())
                ->setLabelText(__('KMS::global.metaDescription'))
                ->setReference('meta_description')
        ]);

        $componentArea = (new ComponentArea())
            ->setReference('dynamic_group_sections')
            ->setComponentTypes(ComponentTypes::all())
            ->setSubFolder('dynamic_group_sections');
        if($currentModel && in_array($currentModel->code_name, ['services'], true)) $componentArea->setStyleClass('hidden');

        $this->tabs->getLanguageTabTemplate()->addItem($componentArea);

    }
}