File: D:/HostingSpaces/SBogers10/slenders.komma.pro/app/Komma/Pages/Kms/PageSection.php
<?php
/**
*
*
* @author Komma <info@komma.pro>
* @copyright (c) 2012-2016, Komma
*/
namespace App\Komma\Pages\Kms;
//The new object oriented attributes
use App\Komma\Components\ComponentType\ComponentTypes;
use App\Komma\Kms\Core\Attributes\Documents;
use App\Komma\Kms\Core\Attributes\ComponentArea;
use App\Komma\Kms\Core\Sections\Section;
use App\Komma\Routes\RouteService;
use App\Komma\Sites\SiteServiceInterface;
use App\Komma\Users\Models\KmsUserRole;
use App\Komma\Kms\Core\Attributes\Attribute;
use App\Komma\Kms\Core\Attributes\Models\ImageProperty;
use App\Komma\Kms\Core\Attributes\OnOff;
use App\Komma\Kms\Core\Attributes\Select;
use App\Komma\Kms\Core\Attributes\Seperator;
use App\Komma\Kms\Core\Attributes\TextArea;
use App\Komma\Kms\Core\Attributes\TextField;
use App\Komma\Kms\Core\Attributes\Title;
use App\Komma\Kms\Core\Sections\CurrentSiteLanguagesTabsDirector;
use App\Komma\Kms\Core\Sections\SectionTabGroups;
use App\Komma\Kms\Core\Sections\SectionTabItem;
use App\Komma\Kms\Core\Sections\SectionTabsBuilder;
use App\Komma\Kms\Core\ValidationSet;
use Illuminate\Database\Eloquent\Collection;
final class PageSection extends Section
{
protected $slug = "pages";
protected $hasRoutes = true;
public $showSave = 'all';
public $showDelete = [1];
public $showCreate = [1];
/**
* PageSection constructor.
* @param PageService $sectionService
* @param RouteService $routeService
* @param SiteServiceInterface $siteService
*/
function __construct(PageService $sectionService, RouteService $routeService, SiteServiceInterface $siteService)
{
$sectionTabDirector = new CurrentSiteLanguagesTabsDirector(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
* @throws \Exception
*/
protected function generateAttributes(): Collection
{
$fixedAttributeTabItems = $this->generateFixedAttributes();
$tabItems = $fixedAttributeTabItems;
$languageIndexedAttributes = $this->createAttributesFromExistingAttributeForCurrentSiteLanguages($this->generateFixedLanguageAttributes());
foreach($languageIndexedAttributes as $attribute) $tabItems->push(new SectionTabItem($attribute, SectionTabGroups::Languages));
return $tabItems;
}
/**
* Generate fixed attributes
*
* @return Collection
*/
private function generateFixedAttributes():Collection {
/** @var PageService $pageService */
$pageService = $this->getSectionService();
//*****************************************************************************************\\
//*** Define attribute validation sets ***\\
//*****************************************************************************************\\
$codeNameValidationSet = (new ValidationSet())
->setRules('required')
->setMessages(['required' => __('validation.required')]);
//*****************************************************************************************\\
//*** Generate the attributes ***\\
//*****************************************************************************************\\
$attributes = [];
//Build the general attributes and put them in the attributes array
$attributes[] = (new Title(__('kms/sites.type')));
$attributes[] = (new TextField(__('kms/sites.type')))
->setReadOnly(true)
->mapValueFrom(Attribute::ValueFromItself, 'site_name');
$attributes[] = (new Seperator());
$attributes[] = (new Title(__('kms/pages.page')));
// $attributes[] = (new Video('Youtube'));
$attributes[] = (new TextField(__('kms/global.codeName')))
->setPlaceholderText(__('kms/global.enterCodeName'))
->setMinimumUserRole(KmsUserRole::SuperAdmin)
->setReadOnly(false)
->mapValueFrom(Attribute::ValueFromModel, 'code_name')
->setValidationSet($codeNameValidationSet);
$attributes[] = (new OnOff())
->setLabelText(__('kms/global.active'))
->switchOn()
->mapValueFrom(Attribute::ValueFromModel, 'active');
$pageOptionModels = $pageService->getOptionsForSelect();
$attributes[] = (new Select())
->setItems($pageOptionModels->toArray())
->setLabelText(__('kms/pages.parent_page'))
->setExcludeCurrentModelItem(true)
->mapValueFrom(Attribute::ValueFromModel, 'parent_id');
$attributes[] = (new Documents())
->setLabelText(__('kms/global.images'))
// ->onlyAllowImages()
->setMaxDocuments(5)
->setSubFolder('pages')
->mapValueFrom(Attribute::ValueFromDocuments, 'pages');
$attributes[] = (new Seperator());
//****************************************************************************************************************************************\\
//*** 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;
}
public function generateFixedLanguageAttributes() {
$model = $this->getModel();
if(!$componentTypes = ComponentTypes::getSet($model->code_name)) $componentTypes = ComponentTypes::all();
$attributes = [];
$attributes[] = (new TextField(__('kms/global.title')))
->setPlaceholderText(__('kms/global.enterTitle'))
->mapValueFrom(Attribute::ValueFromTranslationModel, 'name');
$attributes[] = (new Seperator());
// ------------------------------------ Load page specific attributes -----------------------------------------------
if($model->exists && $model->code_name == 'home') {
$attributes[] = (new TextArea())
->setLabelText(__('kms/pages.streamer'))
->setPlaceholderText(__('kms/pages.enterStreamer'))
->mapValueFrom(Attribute::ValueFromTranslationModel, 'streamer');
$attributes[] = (new Seperator());
}
if($model->exists && in_array($model->code_name, ['interior', 'sleeping', 'living'])) {
$attributes[] = (new TextArea())
->setLabelText(__('kms/pages.description'))
->setPlaceholderText(__('kms/pages.enterDescription'))
->mapValueFrom(Attribute::ValueFromTranslationModel, 'description');
$attributes[] = (new Seperator());
}
// ---------------------------------------------------------------------------------------------------------------------
$attributes[] = (new Title(__('kms/pages.seo')));
$attributes[] = (new TextField(__('kms/global.metaTitle')))
->setPlaceholderText(__('kms/global.enterTitle'))
->mapValueFrom(Attribute::ValueFromTranslationModel, 'meta_title');
$attributes[] = (new TextArea())
->setLabelText(__('kms/global.metaDescription'))
->setPlaceholderText(__('kms/global.enterMetaDescription'))
->mapValueFrom(Attribute::ValueFromTranslationModel, 'meta_description');
$attributes[] = (new ComponentArea())
->setComponentTypes($componentTypes)
->setSubFolder('dynamic_group_sections')
->mapValueFrom(Attribute::ValueFromComponentArea, 'dynamic_group_sections');
return $attributes;
}
/**
* This method will stop the load entities of the kmsSiteSection
*
* @return array
*
*/
public function loadEntities(){
return [];
}
}