File: D:/HostingSpaces/SBogers10/blije-gasten.komma.pro/app/Komma/Questions/Kms/QuestionSection.php
<?php
/**
*
*
* @author Komma <info@komma.pro>
* @copyright (c) 2012-2016, Komma
*/
namespace App\Komma\Questions\Kms;
//The new object oriented attributes
use App\Komma\Kms\Core\Sections\Section;
use App\Komma\Kms\Core\Attributes\Attribute;
use App\Komma\Kms\Core\Attributes\OnOff;
use App\Komma\Kms\Core\Attributes\TextArea;
use App\Komma\Kms\Core\Attributes\TextField;
use App\Komma\Kms\Core\Sections\Tabs\Collections\NoLanguageTabs;
use App\Komma\Kms\Core\ValidationSet;
use App\Komma\Shop\Vies\Rules\VatNumber;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
final class QuestionSection extends Section
{
/**
* PageSection constructor.
* @param $slug
*/
// function __construct(Kms $kms, PageRepository $repository)
function __construct($slug)
{
$tabs = new NoLanguageTabs();
parent::__construct($tabs, $slug);
}
/**
* 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()
* @param Model $currentModel
* @return Collection A collection of SectionTabItems
*/
protected function generateAttributes(Model $currentModel = null): Collection
{
// \Log::info("PageSection::Generating attributes");
//*****************************************************************************************\\
//*** Define attribute validation sets ***\\
//*****************************************************************************************\\
$requiredValidationSet = (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 OnOff())
->setLabelText(__('kms/global.active'))
->switchOn()
->mapValueFrom(Attribute::ValueFromModel, 'active');
//Build an array with attributes for each current site language
$languageIndexedAttributes = $this->createAttributesFromExistingAttributeForCurrentSiteLanguages([
(new TextField(__('kms/global.title')))
->setPlaceholderText(__('kms/global.enterTitle'))
->mapValueFrom(Attribute::ValueFromTranslationModel, 'name'),
(new TextArea())
->setLabelText(__('kms/global.description'))
->setPlaceholderText(__('kms/global.enterDescription'))
->enableTinymceEditor()
->mapValueFrom(Attribute::ValueFromTranslationModel, 'description'),
]);
//Return all attributes as a collection
return collect(array_merge($attributes, $languageIndexedAttributes));
}
/**
* Adds attributes to their appropriate tabs.
*
* @param Collection $attributeCollection
* @return void
*/
protected function addAttributesToTabs(Collection $attributeCollection)
{
$attributeCollection->each(function(Attribute $attribute) {
$this->tabs->getTab(__('kms/global.general'))->addItem($attribute);
});
}
}