File: D:/HostingSpaces/SBogers10/blije-gasten.komma.pro/app/Komma/Shop/Properties/Kms/PropertySection.php
<?php
namespace App\Komma\Shop\Properties\Kms;
use App\Komma\Kms\Core\Attributes\Attribute;
use App\Komma\Kms\Core\Attributes\TextField;
use App\Komma\Kms\Core\Attributes\Title;
use App\Komma\Kms\Core\Sections\Section;
use App\Komma\Kms\Core\Sections\Tabs\Collections\AllUsedLanguagesTabs;
use App\Komma\Kms\Core\ValidationSet;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
class PropertySection extends Section
{
protected $title = "Properties";
protected $subtitle = "All properties";
protected $slug = "properties";
/**
* PropertySection constructor.
*
* @param string $slug
*/
function __construct(string $slug)
{
if(app()->runningInConsole()) return;
$this->title = ucfirst(__("shop/properties.properties"));
$tabs = new AllUsedLanguagesTabs();
parent::__construct($tabs, 'properties');
}
/**
* 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
{
//*****************************************************************************************\\
//*** Define attribute validation sets ***\\
//*****************************************************************************************\\
$nameValidationSet = (new ValidationSet())
->setRules([
'required',
// Rule::unique((new PropertyKeyTranslation())->getTable(), 'value')->ignore($model->key()->first()->id)
])
->setMessages([
'required' => __('validation.required'),
// 'unique' => __('kms/kms_users.enterUniqueValue')
]);
//*****************************************************************************************\\
//*** Generate the attributes ***\\
//*****************************************************************************************\\
$attributes = [];
//Build the general attributes and put them in the attributes array
$attributes[] = (new Title(__('shop/properties.property')));
$attributes[] = (new TextField(__('kms/global.codeName')))
->mapValueFrom(Attribute::ValueFromModel, 'code_name');
//Build an array with attributes for each current site language
$languageIndexedAttributes = $this->createAttributesFromExistingAttributeForAllUsedLanguagesBySites([
(new Title(__('shop/properties.name'))),
(new TextField(__('shop/properties.name')))
->setExplanation(__('shop/properties.key_explanation'))
->mapValueFrom(Attribute::ValueFromItself, 'key')
->setValidationSet($nameValidationSet),
(new TextField(__('shop/properties.value')))
->setExplanation(__('shop/properties.values_explanation'))
->mapValueFrom(Attribute::ValueFromItself, 'value')
]);
//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 [];
}
}