File: D:/HostingSpaces/SBogers10/ste.komma.pro/app/MethodSteps/Kms/MethodStepSection.php
<?php
/**
*
*
* @author Komma <info@komma.pro>
* @copyright (c) 2012-2016, Komma
*/
namespace App\MethodSteps\Kms;
//The new object oriented attributes
use App\Base\SectionWithSiteLogic;
use App\MethodSteps\Models\MethodStep;
use App\QuestionCategories\Models\QuestionCategory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
use Komma\KMS\Core\Attributes\Attribute;
use Komma\KMS\Core\Attributes\OnOff;
use Komma\KMS\Core\Attributes\Select;
use Komma\KMS\Core\Attributes\TextArea;
use Komma\KMS\Core\Attributes\TextField;
use Komma\KMS\Core\ModelServiceInterface;
use Komma\KMS\Core\Sections\Tabs\Collections\AllUsedLanguagesTabs;
use Komma\KMS\Core\ValidationSet;
final class MethodStepSection extends SectionWithSiteLogic
{
/**
* PageSection constructor.
* @param $slug
*/
// function __construct(Kms $kms, PageRepository $repository)
function __construct($slug)
{
$tabs = new AllUsedLanguagesTabs();
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
{
// \Log::info("PageSection::Generating attributes");
//*****************************************************************************************\\
//*** Define attribute validation sets ***\\
//*****************************************************************************************\\
$requiredValidationSet = (new ValidationSet())
->setRules('required')
->setMessages(['required' => __('validation.required')]);
//*****************************************************************************************\\
//*** Generate the attributes ***\\
//*****************************************************************************************\\
$attributes = [];
/** @var ModelServiceInterface $steLanguageModelService */
$methodStepService = app(ModelServiceInterface::class);
$methodStepService->setModelClassName(MethodStep::class);
$attributes[] = (new Select())
->setItems($methodStepService->getOptionsForSelectAsTree()->toArray())
->setLabelText(__('kms/pages.parent_page'))
->setExcludeCurrentModelItem(true)
->setStyleClass('hidden')
->mapValueFrom(\App\Attributes\Attribute::ValueFromItself, 'parent_id');
//Build an array with attributes for each current site language
$languageIndexedAttributes = $this->createAttributesFromExistingAttributeForAllUsedLanguagesBySites([
(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));
}
}