File: D:/HostingSpaces/SBogers10/inzigd.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\Role;
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([
(new ComponentArea())
->setComponentTypes(ComponentTypes::all())
->setSubFolder('dynamic_group_sections')
->mapValueFrom(Attribute::ValueFromComponentArea, 'dynamic_group_sections')
]);
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)
->setStyleClass('hidden')
->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(Role::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)
// ->setStyleClass('hidden')
->mapValueFrom(Attribute::ValueFromModel, 'parent_id');
$attributes[] = (new Documents())
->setLabelText(__('kms/global.images'))
->onlyAllowImages()
->setSmallDragAndDropArea()
->setMaxDocuments(1)
->setSubFolder('pages')
->setImageProperties([
(new ImageProperty())->setName('thumb')->setCropMethod(ImageProperty::Fit)->setWidth(100),
(new ImageProperty())->setName('small')->setCropMethod(ImageProperty::Resize)->setWidth(350),
(new ImageProperty())->setName('medium')->setCropMethod(ImageProperty::Resize)->setWidth(600),
(new ImageProperty())->setName('large')->setCropMethod(ImageProperty::Resize)->setWidth(1200),
(new ImageProperty())->setName('original')->setCropMethod(ImageProperty::Resize)->setWidth(2000),
])
->mapValueFrom(Attribute::ValueFromDocuments, 'pages');
$attributes[] = (new Seperator());
//Build an array with attributes for each current site language
$languageIndexedAttributes = $this->createAttributesFromExistingAttributeForCurrentSiteLanguages([
(new Title(__('kms/global.information'))),
(new TextField(__('kms/global.title')))
->setPlaceholderText(__('kms/global.enterTitle'))
->mapValueFrom(Attribute::ValueFromTranslationModel, 'name'),
(new TextArea())
->setLabelText(__('kms/global.description'))
->setPlaceholderText(__('kms/global.enterDescription'))
->mapValueFrom(Attribute::ValueFromTranslationModel, 'description'),
(new Seperator()),
(new Title(__('kms/global.seo'))),
(new TextField(__('kms/global.metaTitle')))
->setPlaceholderText(__('kms/global.enterTitle'))
->mapValueFrom(Attribute::ValueFromTranslationModel, 'meta_title'),
(new TextArea())
->setLabelText(__('kms/global.metaDescription'))
->setPlaceholderText(__('kms/global.enterMetaDescription'))
->mapValueFrom(Attribute::ValueFromTranslationModel, 'meta_description'),
]);
//****************************************************************************************************************************************\\
//*** 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) $tabItems->push(new SectionTabItem($attribute, SectionTabGroups::Languages));
return $tabItems;
}
/**
* This method will stop the load entities of the kmsSiteSection
*
* @return array
*
*/
public function loadEntities(){
return [];
}
}