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/Products/ProductGroup/ProductGroupSection.php
<?php
namespace App\Products\ProductGroup;

//The new object oriented attributes
use App\Products\Product\Product;
use App\Products\ProductGroupDisplayEnum;
use App\Properties\Kms\PropertyKeyService;
use Komma\KMS\Core\Attributes\Attribute;
use Komma\KMS\Core\Attributes\Models\SelectOption;
use Komma\KMS\Core\Attributes\MultiSelect;
use Komma\KMS\Core\Attributes\Documents;
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\Core\Sections\Section;
use App\Categories\Kms\CategoryModelService;
use App\Properties\Kms\PropertyService;
use Illuminate\Database\Eloquent\Model;
use Komma\KMS\Sites\SiteServiceInterface;

class ProductGroupSection extends Section
{
    /**
     * Define the attributes and tabs for this section.
     *
     * @param Model $currentModel
     */
    public function defineAttributesAndTabs(Model $currentModel = null): void
    {
        $categoryService = \App::make(CategoryModelService::class);
        $propertyKeyService = new PropertyKeyService();
        $productGroupService = new ProductGroupModelService();
        $siteService = app(SiteServiceInterface::class);

        $attributes = [];

        //Build the general attributes and put them in the attributes array
        //Category selection
        $attributes[] = (new Title())
        ->setLabelText(__('KMS::categories.category'));

        $categoryOptionModels = $categoryService->getOptionsForSelect();
        $attributes[] = (new MultiSelect())
            ->setItems($categoryOptionModels->toArray())
            ->setLabelText(__('KMS::categories.category'))
            ->mapValueFrom(Attribute::ValueFromModelHasManyRelation, 'categories|id');

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

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

        //Site selection
        $attributes[] = (new Title())
        ->setLabelText(__('KMS::sites.type'));

        $siteOptionModels = $siteService->getOptionsForSelect();
        $attributes[] = (new MultiSelect())
            ->setItems($siteOptionModels->toArray())
            ->setLabelText(__('KMS::sites.type'))
            ->mapValueFrom(Attribute::ValueFromItself, 'site_id');
        $attributes[] = (new Seperator());

        $attributes[] = (new Title())
        ->setLabelText(__('KMS::products.product'));

        $attributes[] = (new OnOff())
            ->setLabelText(__('KMS::global.active'))
            ->switchOn()
            ->setReference( 'active');

        $productOptionModels = $productGroupService->getOptionModelsForProductSelect();
        $attributes[] = (new MultiSelect())
            ->setItems($productOptionModels)
            ->setLabelText(__('KMS::products.products'))
            ->enableSortable()
            ->mapValueFrom(Attribute::ValueFromModelHasManyRelation, 'products|id');

        $attributes[] = (new Select())
        ->setItems([
            (new SelectOption())
                ->setContent(__('KMS::products.list'))
                ->setHtmlContent(__('KMS::products.list'))
                ->setValue(ProductGroupDisplayEnum::LIST),
            (new SelectOption())
                ->setContent(__('KMS::products.variant_select'))
                ->setHtmlContent(__('KMS::products.variant_select'))
                ->setValue(ProductGroupDisplayEnum::VARIANT_SELECT)
        ])->setLabelText(__('KMS::products.display_as'))
        ->setReference( 'display_as');

        $productBehaviourOptionModels = $productGroupService->getOptionModelsForBehaviourSelect();
        $attributes[] = (new Select())
            ->setItems($productBehaviourOptionModels)
            ->setLabelText(__('KMS::products.behaviour'))
            ->setReference( 'product_group_behaviour_id');

        $attributes[] = (new OnOff())
            ->setLabelText(__('KMS::products.group_products'))
            ->mapValueFrom(Attribute::ValueFromModel, 'group_products');

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

        $propertyKeyOptions = $propertyKeyService->getOptionsForSelect();
        $attributes[] = (new MultiSelect())
            ->setItems($propertyKeyOptions->toArray())
            ->setLabelText(__('KMS::properties.filterable_on'))
            ->enableSortable()
            ->mapValueFrom(Attribute::ValueFromModelHasManyRelation, 'filterPropertyKeys|id');

        $this->tabs->makeTab()->addItems($attributes);

        //Build an array with attributes for each current site language
        $languageAttributes = [];
        if($currentModel) {
            $languageAttributes[] = (new TextField())
                ->setLabelText(__('KMS::global.updated_at'))
                ->setReadOnly(true)
                ->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 TextArea())
            ->setLabelText(__('KMS::global.metaDescription'))
            ->setPlaceholderText(__('KMS::global.enterMetaDescription'))
            ->setReference( 'meta_description');

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

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

    /**
     * This method will stop the load entities of the kmsSiteSection
     *
     * @return array
     *
     */
    public function loadEntities(){
        return [];
    }
}