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/SBogers95/rentman.io/app/Komma/ProductGroups/Kms/ProductGroupSection.php
<?php

namespace App\Komma\ProductGroups\Kms;

use App\Komma\Kms\Core\Attributes\Attribute;
use App\Komma\Kms\Core\Attributes\TextField;
use App\Komma\Kms\Core\Sections\NoLanguageTabsDirector;
use App\Komma\Kms\Core\Sections\Section;
use App\Komma\Kms\Core\Sections\SectionTabGroups;
use App\Komma\Kms\Core\Sections\SectionTabItem;
use App\Komma\Kms\Core\Sections\SectionTabsBuilder;
use App\Komma\Routes\RouteService;
use App\Komma\Sites\SiteServiceInterface;
use Illuminate\Database\Eloquent\Collection;

class ProductGroupSection extends Section
{
    protected $slug = 'productgroups';

    /**
     * PageSection constructor.
     * @param ProductGroupService $sectionService
     * @param RouteService $routeService
     * @param SiteServiceInterface $siteService
     */
//    function __construct(Kms $kms, PageRepository $repository)
    public function __construct(ProductGroupService $sectionService, RouteService $routeService, SiteServiceInterface $siteService)
    {
        $sectionTabDirector = new NoLanguageTabsDirector(new SectionTabsBuilder()); //Can make tabs for us. also see KmsSection::__construct

        parent::__construct($sectionService, $routeService, $siteService, $sectionTabDirector);
    }

    /**
     * Generates the attributes for this section. They all must extend the App\Komma\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()
     * @return Collection A collection of SectionTabItems
     */
    protected function generateAttributes(): Collection
    {
        //*****************************************************************************************\\
        //*** Generate the attributes                                                           ***\\
        //*****************************************************************************************\\
        $attributes = [];

        //Build the general attributes and put them in the attributes array
        //Site selection
//        $attributes[] = (new Title(__('kms/sites.type')));

        //Build an array with attributes for each current site language
        $languageIndexedAttributes = $this->createAttributesFromExistingAttributeForAllUsedLanguagesBySites([
            (new TextField(__('kms/global.name')))
                ->setPlaceholderText(__('kms/global.enterName'))
                ->mapValueFrom(Attribute::ValueFromTranslationModel, 'name'),
        ]);

        //****************************************************************************************************************************************\\
        //*** Put the all attributes in a SectionTabItem so we can track for which tab they are. And then put SectionTabItems in a Collection  ***\\
        //****************************************************************************************************************************************\\
        $tabItems = new Collection();

        foreach ($attributes as $attribute) {
            $tabItems->push(new SectionTabItem($attribute, SectionTabGroups::General));
        }
        foreach ($languageIndexedAttributes as $attribute) {
            // Also add the iso to the label so we can put it on one tab
            $attribute->setLabelText($attribute->getAssociatedLanguage()->iso_2.':&nbsp;&nbsp;&nbsp;'.$attribute->getLabelText());
            $tabItems->push(new SectionTabItem($attribute, SectionTabGroups::General));
        }

        return $tabItems;
    }

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