File: D:/HostingSpaces/SBogers10/ste.komma.pro/app/Pages/Kms/PageSection.php
<?php
/**
*
*
* @author Komma <info@komma.pro>
* @copyright (c) 2012-2016, Komma
*/
namespace App\Pages\Kms;
//The new object oriented attributes
use App\Attributes\Attribute;
use App\Attributes\ComponentArea;
use App\Base\SectionWithSiteLogic;
use App\Components\ComponentType\ComponentTypes;
use Komma\KMS\Core\Attributes\Documents;
use Komma\KMS\Core\ModelServiceInterface;
use Komma\KMS\Core\Sections\Tabs\Collections\CurrentSiteLanguagesTabs;
use App\Pages\Models\Page;
use Komma\KMS\Sites\SiteServiceInterface;;
use Komma\KMS\Core\Attributes\Models\ImageProperty;
use Komma\KMS\Core\Attributes\OnOff;
use Komma\KMS\Core\Attributes\Select;
use Komma\KMS\Core\Attributes\Seperator;
use Komma\KMS\Core\Attributes\TextArea;
use Komma\KMS\Core\Attributes\TextField;
use Komma\KMS\Core\Attributes\Title;
use Komma\KMS\Core\ValidationSet;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
use Komma\KMS\Users\Models\KmsUserRole;
final class PageSection extends SectionWithSiteLogic
{
/**
* PageSection constructor.
* @param $slug
*/
function __construct(string $slug)
{
$tabs = new CurrentSiteLanguagesTabs();
$this->siteService = app(SiteServiceInterface::class);
parent::__construct($tabs, $slug);
}
/**
* Generates the attributes for this section. They all must extend the App\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()
* @param Model $currentModel
* @return Collection A collection of SectionTabItems
*/
protected function generateAttributes(Model $currentModel = null): Collection
{
$fixedAttributeTabItems = $this->generateFixedAttributes($currentModel);
$tabItems = $fixedAttributeTabItems;
$languageIndexedAttributes = $this->createAttributesFromExistingAttributeForCurrentSiteLanguages([
(new ComponentArea())
->setComponentTypes([
ComponentTypes::NAMED_TEXT,
ComponentTypes::TEXT_IMAGE,
ComponentTypes::DOUBLE_TEXT,
ComponentTypes::VIDEO,
ComponentTypes::TEXT,
ComponentTypes::IMAGE,
ComponentTypes::TEXT_USP,
ComponentTypes::REFERENCES,
])
->setSubFolder('dynamic_group_sections')
->mapValueFrom(Attribute::ValueFromComponentArea, 'dynamic_group_sections')
]);
return $tabItems->merge(collect($languageIndexedAttributes));
}
/**
* Generate fixed attributes
*
* @param Model|null $currentModel
* @return Collection
*/
private function generateFixedAttributes(Model $currentModel = null):Collection {
/** @var ModelServiceInterface $pageModelService */
$pageModelService = app(ModelServiceInterface::class);
$pageModelService->setModelClassName(Page::class);
//*****************************************************************************************\\
//*** Define attribute validation sets ***\\
//*****************************************************************************************\\
$codeNameValidationSet = (new ValidationSet())
->setRules('required')
->setMessages(['required' => __('validation.required')]);
$hasWildcardValidationSet = (new ValidationSet())
->setRules(['sometimes', 'required', 'integer'])
->setMessages([
'sometimes' => __('validation.required'),
'required' => __('validation.required'),
'min' => __('validation.min.numeric'),
]);
//*****************************************************************************************\\
//*** Generate the attributes ***\\
//*****************************************************************************************\\
$attributes = [];
$attributes[] = (new OnOff())
->setLabelText(__('kms/global.active'))
->switchOn()
->mapValueFrom(Attribute::ValueFromModel, 'active');
$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.uses_wildcard'))
->setExplanation(__('KMS::kms/pages.wildcard_explanation'))
->setMinimumUserRole(KmsUserRole::SuperAdmin)
->setValidationSet($hasWildcardValidationSet)
->mapValueFrom(Attribute::ValueFromModel, 'has_wildcard');
$pageOptionModels = $pageModelService->getOptionsForSelectAsTree();
$attributes[] = (new Select())
->setItems($pageOptionModels->toArray())
->setLabelText(__('kms/pages.parent_page'))
->setExcludeCurrentModelItem(true)
->setMinimumUserRole(KmsUserRole::SuperAdmin)
->mapValueFrom(Attribute::ValueFromItself, 'parent_id');
// $attributes[] = (new Video('Youtube'));
$documentAttribute = (new Documents())
->setLabelText('Afbeelding')
->onlyAllowImages()
->setMaxDocuments(1)
->setSubFolder('pages')
->setImageProperties([
(new ImageProperty())->setName('thumb')->setCropMethod(ImageProperty::Fit)->setWidth(100),
(new ImageProperty())->setName('small')->setCropMethod(ImageProperty::Resize)->setWidth(450),
(new ImageProperty())->setName('medium')->setCropMethod(ImageProperty::Resize)->setWidth(1000),
(new ImageProperty())->setName('large')->setCropMethod(ImageProperty::Resize)->setWidth(1800),
])
->setSmallDragAndDropArea()
->mapValueFrom(Attribute::ValueFromDocuments, 'pages');
if($currentModel && $currentModel->exists && in_array($currentModel->code_name, ['home', 'about', 'method', 'contact', 'intake'])) {
}
else $documentAttribute->setStyleClass('hidden');
$attributes[] = $documentAttribute;
//Build an array with attributes for each current site language
$languageIndexedAttributes = $this->createAttributesFromExistingAttributeForCurrentSiteLanguages([
(new TextField(__('kms/global.title')))
->setPlaceholderText(__('kms/global.enterTitle'))
->setMinimumUserRole(KmsUserRole::SuperAdmin)
->mapValueFrom(Attribute::ValueFromTranslationModel, 'name'),
(new Seperator()),
(new Title('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'),
]);
//Return all attributes as a collection
return collect(array_merge($attributes, $languageIndexedAttributes));
}
/**
* This method will stop the load entities of the kmsSiteSection
*
* @return array
*
*/
public function loadEntities(){
return [];
}
}