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/brameda/brameda.nl/app/Komma/Kms/Core/Sections/AllUsedLanguagesTabsDirector.php
<?php

namespace App\Komma\Kms\Core\Sections;

use App\Komma\Sites\Models\Site;

/**
 * This should be used when you have a multi site model
 * Then it will load all languages which are used in all defined sites
 *
 * Class AllUsedLanguagesTabsDirector
 * @package App\Komma\Kms\Core\Sections
 */
class AllUsedLanguagesTabsDirector extends AbstractSectionTabsDirector
{
    /**
     * @var $sectionTabBuilder AbstractSectionTabsBuilder
     */
    private $sectionTabBuilder;

    public function __construct(AbstractSectionTabsBuilder $sectionTabBuilder)
    {
        $this->sectionTabBuilder = $sectionTabBuilder;
        parent::__construct($sectionTabBuilder);
    }

    /**
     * Builds the tabs for the page section via the builder it is given.
     * Creates a general tab and tabs for each current language.
     */
    function buildTabs(): void
    {
        $this->sectionTabBuilder->getOrCreateTab(__('kms/global.general'), SectionTabGroups::General);

        $languages = Site::has('languages')->with(['languages'])->get()->map(function(Site $site) {
            return $site->languages;
        })->collapse();
        $currentSiteDefaultLanguage = $this->siteService->getCurrentSite()->defaultLanguage;
        $languages = $languages->push($currentSiteDefaultLanguage)->unique('id');

        foreach($languages as $language)
        {
            $this->sectionTabBuilder->getOrCreateTab($language->iso_2, SectionTabGroups::Languages);
        }
    }

    /**
     * Returns a collection that holds multiple
     *
     * @return SectionTabsCollectionInterface
     */
    function getTabsCollection(): SectionTabsCollectionInterface
    {
        return $this->sectionTabBuilder->getTabsCollection();
    }
}