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/douven.komma.pro/app/KommaApp/Sites/Kms/SiteSection.php
<?php

namespace App\KommaApp\Sites\Kms;

use App\KommaApp\Kms\Core\Attributes\Attribute;
use App\KommaApp\Kms\Core\Attributes\AutocompleteInput;
use App\KommaApp\Kms\Core\Attributes\TextField;
use App\KommaApp\Kms\Core\Attributes\Title;
use App\KommaApp\Kms\Core\Sections\NoLanguageTabsDirector;
use App\KommaApp\Kms\Core\Sections\Section;
use App\KommaApp\Kms\Core\Sections\SectionTabGroups;
use App\KommaApp\Kms\Core\Sections\SectionTabItem;
use App\KommaApp\Kms\Core\Sections\SectionTabsBuilder;
use App\KommaApp\Kms\Core\Sections\SectionTabsCollection;
use App\KommaApp\Languages\Kms\LanguageService;
use App\KommaApp\Routes\RouteService;
use App\KommaApp\Users\Roles;
use Illuminate\Database\Eloquent\Collection;

//class SiteSection extends KmsSection
class SiteSection extends Section
{
    protected $title = "Sites";
    protected $subTitle = "";
    protected $slug = "sites";

    public $showDelete = [Roles::SuperAdmin];
    public $showCreate = [Roles::SuperAdmin];

    private $languageService;

    /**
     * SiteSection constructor.
     * @param SiteService $siteService
     * @param RouteService $routeService
     * @param LanguageService $languageService
     */
    function __construct(SiteService $siteService, RouteService $routeService, LanguageService $languageService)
    {
        $sectionTabDirector = new NoLanguageTabsDirector(new SectionTabsBuilder()); //Can make tabs for us. also see KmsSection::__construct

        $this->title = __('kms/sites.title');
        $this->subTitle = __('kms/sites.sub_title');

        $this->languageService = $languageService;

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

    /**
     * Generates the attributes for this section. They all must extend the App\KommaApp\Kms\Core\Attributes\Attribute class
     *
     * @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
        $attributes[] = (new Title(__('kms/global.information')));

        $attributes[] = (new TextField(__('kms/global.name')))
            ->setPlaceholderText(__('kms/sites.enter_name'))
            ->setReadOnly(false)
            ->mapValueFrom(Attribute::ValueFromModel, 'name');

        $attributes[] = (new TextField(__('kms/sites.slug')))
            ->setPlaceholderText(__('kms/sites.enter_slug'))
            ->setReadOnly(false)
            ->mapValueFrom(Attribute::ValueFromModel, 'slug');

        $languageOptionsModels = $this->languageService->getAvailableLanguagesForSites();
        $attributes[] = (new AutocompleteInput())
            ->setItems($languageOptionsModels)
            ->setLabelText(__('kms/sites.languages'))
            ->mapValueFrom(Attribute::ValueFromModelHasManyRelation, 'languages|id');

        //****************************************************************************************************************************************\\
        //*** 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));

        return $tabItems;
    }


}