File: D:/HostingSpaces/SBogers10/shop.komma.nl/app/Posts/Kms/PostSection.php
<?php
namespace App\Posts\Kms;
use App\Components\ComponentTypes;
use Komma\KMS\Core\Attributes\Attribute;
use Komma\KMS\Core\Attributes\ComponentArea;
use Komma\KMS\Core\Attributes\MultiSelect;
use Komma\KMS\Core\Attributes\DatePicker;
use Komma\KMS\Core\Attributes\Documents;
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\Sections\Section;
use Illuminate\Database\Eloquent\Model;
use Komma\KMS\Sites\SiteServiceInterface;
use Komma\KMS\Users\Kms\KmsUserService;
final class PostSection extends Section
{
/**
* 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
*/
public function defineAttributesAndTabs(Model $currentModel = null): void
{
$siteService = app(SiteServiceInterface::class);
$kmsUserService = new KmsUserService();
$siteOptionModels = $siteService->getOptionsForSelect();
$authorOptionsModels = $kmsUserService->getOptionsForSelect();
$this->tabs->makeTab()->addItems([
(new MultiSelect())
->setItems($siteOptionModels->toArray())
->setLabelText(__('KMS::sites.type'))
->mapValueFrom(Attribute::ValueFromItself, 'site_id'),
(new OnOff())
->setLabelText(__('KMS::global.active'))
->switchOn()
->setReference( 'active'),
(new DatePicker())
->setReference('date')
->setLabelText(__('KMS::global.date')),
// ->setTimeEnabled(false),
(new MultiSelect())
->setItems($authorOptionsModels->toArray())
->setLabelText(__('KMS::posts.author'))
->setMaxItemsToSelect(1)
->setRules('required')
->setReference( 'author_id'),
(new Documents())
->setLabelText(__('KMS::global.image'))
->onlyAllowImages()
->setMaxDocuments(1)
->setSubFolder('posts')
->mapValueFrom(Attribute::ValueFromDocuments, 'posts')
]);
//Build an array with attributes for each current site language
$languageAttributes = [];
if($currentModel) {
$languageAttributes[] = (new TextField())
->setLabelText(__('KMS::global.updated_at'))
->setReadOnly(true)
->setReference( 'updated_at');
}
$languageAttributes[] = (new Title())
->setLabelText(__('KMS::global.information'));
$languageAttributes[] = (new TextField())
->setLabelText(__('KMS::global.title'))
->setPlaceholderText(__('KMS::global.enterTitle'))
->setReference( 'name');
$languageAttributes[] = (new Seperator());
$languageAttributes[] = (new TextArea())
->setLabelText(__('KMS::global.metaDescription'))
->setPlaceholderText(__('KMS::global.enterMetaDescription'))
->setReference( 'meta_description');
$languageAttributes[] = (new ComponentArea())
->setSubFolder('post_component_data')
->setComponentTypes([
ComponentTypes::TEXT,
ComponentTypes::IMAGE
])
->mapValueFrom(Attribute::ValueFromComponentArea, 'post_components');
$this->tabs->makeLanguageTabTemplate()->addItems($languageAttributes);
}
/**
* This method will stop the load entities of the kmsSiteSection
*
* @return array
*
*/
public function loadEntities(){
return [];
}
}