File: D:/HostingSpaces/SBogers10/bomacon.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\Base\SectionWithSiteLogic;
use App\Buttons\Kms\ButtonService;
use App\Components\ComponentType\ComponentTypes;
use App\Pages\Models\Page;
use Illuminate\Database\Eloquent\Model;
use Komma\KMS\Core\Attributes\Documents;
use App\Attributes\ComponentArea;
use Komma\KMS\Core\Attributes\Models\SelectOption;
use Komma\KMS\Core\Attributes\MultiSelect;
use Komma\KMS\Core\ModelServiceInterface;
use App\Servicepoints\Kms\ServicepointService;
use App\Servicepoints\Models\Servicepoint;
use Komma\KMS\Core\Sections\Tabs\Collections\CurrentSiteLanguagesTabs;
use Komma\KMS\Sites\SiteServiceInterface;
use Komma\KMS\Users\Models\KmsUserRole;
use Komma\KMS\Core\Attributes\Models\ImageProperty;
use Komma\KMS\Core\Attributes\OnOff;
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\Support\Collection;
final class PageSection extends SectionWithSiteLogic
{
protected $slug = "pages";
protected $hasRoutes = true;
public $showSave = 'all';
public $showDelete = [1];
public $showCreate = [1];
/**
* 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.
*
* @param Model $currentModel
* @return \Illuminate\Support\Collection A collection of SectionTabItems
* @see PageRepository::saveModel()
*/
protected function generateAttributes(Model $currentModel = null): Collection
{
$fixedAttributeTabItems = $this->generateFixedAttributes($currentModel);
$tabItems = $fixedAttributeTabItems;
$languageAttributes = [];
$componentArea = (new ComponentArea())
->setComponentTypes([
ComponentTypes::TEXT_IMAGE,
ComponentTypes::DOUBLE_TEXT,
ComponentTypes::VIDEO,
ComponentTypes::TEXT,
ComponentTypes::IMAGE,
ComponentTypes::DOUBLE_IMAGE,
ComponentTypes::USP,
ComponentTypes::QUOTE,
ComponentTypes::CONTENT_PERSONAL,
ComponentTypes::CONTENT_SLIDER,
ComponentTypes::DOWNLOADS,
])
->setSubFolder('dynamic_group_sections')
->mapValueFrom(Attribute::ValueFromComponentArea, 'dynamic_group_sections');
$languageAttributes[] = $componentArea;
if($currentModel && in_array($currentModel->code_name, ['services'], true)) $componentArea->setStyleClass('hidden');
$languageIndexedAttributes = $this->createAttributesFromExistingAttributeForCurrentSiteLanguages($languageAttributes);
return $tabItems->merge(collect($languageIndexedAttributes));
}
/**
* Generate fixed attributes
*
* @param Model $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 ***\\
//*****************************************************************************************\\
$hasWildcardValidationSet = (new ValidationSet())
->setRules(['sometimes', 'required', 'integer'])
->setMessages([
'sometimes' => __('validation.required'),
'required' => __('validation.required'),
'min' => __('validation.min.numeric'),
]);
//*****************************************************************************************\\
//*** Generate the attributes ***\\
//*****************************************************************************************\\
$attributes = [];
$attributes[] = (new Title(__('KMS::kms/pages.page')));
$attributes[] = (new TextField(__('KMS::kms/global.codeName')))
->setMinimumUserRole(KmsUserRole::SuperAdmin)
->setReadOnly(false)
->mapValueFrom(Attribute::ValueFromModel, 'code_name');
$attributes[] = (new OnOff())
->setLabelText(__('KMS::kms/global.active'))
->setMinimumUserRole(KmsUserRole::SuperAdmin)
->switchOn()
->mapValueFrom(Attribute::ValueFromModel, 'active');
$attributes[] = (new OnOff())
->setLabelText(__('KMS::kms/global.inNav'))
->setMinimumUserRole(KmsUserRole::SuperAdmin)
->mapValueFrom(Attribute::ValueFromModel, 'inNav');
$attributes[] = (new OnOff())
->setLabelText(__('KMS::kms/global.uses_wildcard'))
->setExplanation(__('KMS::kms/pages.wildcard_explanation'))
->setMinimumUserRole(KmsUserRole::SuperAdmin)
->setValidationSet($hasWildcardValidationSet)
->mapValueFrom(Attribute::ValueFromModel, 'has_wildcard');
$attributes[] = (new Seperator())->setMinimumUserRole(KmsUserRole::SuperAdmin);
$attributes[] = (new Documents())
->setLabelText(__('KMS::kms/global.discover_thumbnail'))
->onlyAllowImages()
->setSmallDragAndDropArea()
->setMaxDocuments(1)
->setSubFolder('pages')
->setImageProperties([
(new ImageProperty())->setName('medium')->setCropMethod(ImageProperty::Fit)->setWidth(444)->setHeight(296),
])
->mapValueFrom(Attribute::ValueFromDocuments, 'pages');
$attributes[] = (new Seperator())->setMinimumUserRole(KmsUserRole::SuperAdmin);
$attributes[] = (new Title('CTA uit config overschrijven'))->setMinimumUserRole(KmsUserRole::SuperAdmin);
$attributes[] = (new TextField('Titel'))
->setMinimumUserRole(KmsUserRole::SuperAdmin)
->mapValueFrom(Attribute::ValueFromModel, 'cta_heading');
/** @var ServicepointService $servicepointService */
$servicepointService = \App::make(ServicepointService::class);
$servicepointOptions = $servicepointService->getOptionsForSelect(false, true);
$attributes[] = (new MultiSelect())
->setItems($servicepointOptions->toArray())
->setLabelText(__('Contactpersoon'))
->setMaxItemsToSelect(1)
->canBeLinkedWith(Servicepoint::class)
->setMinimumUserRole(KmsUserRole::SuperAdmin)
->mapValueFrom(Attribute::ValueFromModel, 'servicepoint_id');
/** @var ButtonService $buttonsService */
$buttonsService = \App::make(ButtonService::class);
$buttonModels = $buttonsService->getOptionsForSelect();
$attributes[] = (new MultiSelect())
->setItems($buttonModels->toArray())
->setLabelText('Knop')
->setMinimumUserRole(KmsUserRole::SuperAdmin)
->setMaxItemsToSelect(1)
->mapValueFrom(Attribute::ValueFromModel, 'cta_button_id');
//Get the discover more pages. Except the root page and the current one.
/** @var ModelServiceInterface $pageModelService */
$discoverMorePages = $pageModelService->getOptionsForSelect()->filter(function(SelectOption $pageSelectOption) {
// return $pageSelectOption->getHtmlContent() !== '/' && $pageSelectOption->getHtmlContent() !== $model->getSidebarName(); //Will not because the getSideBarName will not always return the correct name. Needs to be redone properly.
return $pageSelectOption->getHtmlContent() !== '/';
});
$discoverMoreSeparator = (new Seperator())->setMinimumUserRole(KmsUserRole::SuperAdmin);
$discoverMoreTitle = (new Title(__('kms/pages.discover_more')))->setMinimumUserRole(KmsUserRole::SuperAdmin);
$discoverMorePageSelector = (new MultiSelect())
->setItems($discoverMorePages->toArray())
->setLabelText(__('Pagina\'s'))
->mapValueFrom(Attribute::ValueFromModelHasManyRelation, 'discoverPages|id')
->setMinimumUserRole(KmsUserRole::SuperAdmin);
$attributes[] = $discoverMoreSeparator;
$attributes[] = $discoverMoreTitle;
$attributes[] = $discoverMorePageSelector;
if($currentModel && in_array($currentModel->code_name, ['contact', 'vacancies', 'projects', 'services'], true)) {
$discoverMoreSeparator->setStyleClass('hidden');
$discoverMoreTitle->setStyleClass('hidden');
$discoverMorePageSelector->setStyleClass('hidden');
}
//Define language attributes
$languageAttributes = [];
$languageAttributes[] = (new Title(__('KMS::kms/pages.page')));
$languageAttributes[] = (new TextField(__('KMS::kms/global.title')))
->mapValueFrom(Attribute::ValueFromTranslationModel, 'name');
$languageAttributes[] = (new TextField(__('KMS::kms/global.metaTitle')))
->mapValueFrom(Attribute::ValueFromTranslationModel, 'meta_title');
$languageAttributes[] = (new TextArea())
->setLabelText(__('KMS::kms/global.metaDescription'))
->mapValueFrom(Attribute::ValueFromTranslationModel, 'meta_description');
$heroSeperator = (new Seperator())->setMinimumUserRole(KmsUserRole::Admin);
$languageAttributes[] = $heroSeperator;
$heroKmsTitle = (new Title(__('KMS::kms/global.hero')))->setMinimumUserRole(KmsUserRole::Admin);
$languageAttributes[] = $heroKmsTitle;
$heroToggle = (new OnOff())
->setMinimumUserRole(KmsUserRole::Admin)
->setLabelText(__('KMS::kms/global.active'))
->mapValueFrom(Attribute::ValueFromTranslationModel, 'hero_active');
$languageAttributes[] = $heroToggle;
if($currentModel && in_array($currentModel->code_name, ['services'], true)) $heroToggle->setStyleClass('hidden');
$heroTitle = (new TextField(__('KMS::kms/global.heroTitle')))
->setMinimumUserRole(KmsUserRole::Admin)
->mapValueFrom(Attribute::ValueFromTranslationModel, 'hero_title');
$languageAttributes[] = $heroTitle;
$heroDescription = (new TextArea())
->enableTinymceEditor()
->setLabelText(__('kms/global.heroDescription'))
->setMinimumUserRole(KmsUserRole::Admin)
->mapValueFrom(Attribute::ValueFromTranslationModel, 'hero_description');
$languageAttributes[] = $heroDescription;
$heroButtons = (new MultiSelect())
->setItems($buttonModels->toArray())
->setLabelText('Button')
->setMinimumUserRole(KmsUserRole::Admin)
->mapValueFrom(Attribute::ValueFromTranslationModel, 'hero_button_id');
$languageIndexedAttributes[] = $heroButtons;
$heroImages = (new Documents())
->setLabelText(__('KMS::kms/global.images'))
->onlyAllowImages()
->setSmallDragAndDropArea()
->setMaxDocuments(5)
->setMinimumUserRole(KmsUserRole::Admin)
->setSubFolder('page_translations')
->setImageProperties([
(new ImageProperty())->setName('medium')->setCropMethod(ImageProperty::Resize)->setWidth(724),
(new ImageProperty())->setName('small')->setCropMethod(ImageProperty::Resize)->setWidth(359),
])
->mapValueFrom(Attribute::ValueFromDocuments, 'page_translation_heroes');
$languageAttributes[] = $heroImages;
if($currentModel && $currentModel->code_name == 'home') {
$heroSeperator->setStyleClass('hidden');
$heroKmsTitle->setStyleClass('hidden');
$heroToggle->setStyleClass('hidden');
$heroTitle->setStyleClass('hidden');
$heroDescription->setStyleClass('hidden');
$heroImages->setStyleClass('hidden');
$heroButtons->setStyleClass('hidden');
}
//Build an array with attributes for each current site language
$languageIndexedAttributes = $this->createAttributesFromExistingAttributeForCurrentSiteLanguages($languageAttributes);
//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 [];
}
}