File: D:/HostingSpaces/SBogers10/wingssprayer.komma.pro/app/Partners/Kms/PartnerSection.php
<?php
/**
*
*
* @author Komma <info@komma.pro>
* @copyright (c) 2012-2016, Komma
*/
namespace App\Partners\Kms;
//The new object oriented attributes
use App\Attributes\Attribute;
use App\Attributes\ComponentArea;
use App\Base\SectionWithSiteLogic;
use App\Components\ComponentType\ComponentTypes;
use Illuminate\Validation\Rule;
use Komma\KMS\Core\Attributes\Documents;
use Komma\KMS\Core\ModelServiceInterface;
use Komma\KMS\Core\Sections\Tabs\Collections\CurrentSiteLanguagesTabs;
use App\Partners\Models\Partner;
use Komma\KMS\Core\Sections\Tabs\Collections\NoLanguageTabs;
use Komma\KMS\Sites\SiteServiceInterface;
use Komma\KMS\Core\Attributes\Models\ImageProperty;
use Komma\KMS\Core\Attributes\OnOff;
use Komma\KMS\Core\Attributes\Select;
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\Database\Eloquent\Model;
use Illuminate\Support\Collection;
use Komma\KMS\Users\Models\KmsUserRole;
final class PartnerSection extends SectionWithSiteLogic
{
/**
* PartnerSection constructor.
* @param $slug
*/
function __construct(string $slug)
{
$tabs = new NoLanguageTabs();
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 PartnerRepository::saveModel()
* @param Model $currentModel
* @return Collection A collection of SectionTabItems
*/
protected function generateAttributes(Model $currentModel = null): Collection
{
return $this->generateFixedAttributes($currentModel);
}
/**
* Generate fixed attributes
*
* @param Model|null $currentModel
* @return Collection
*/
private function generateFixedAttributes(Model $currentModel = null):Collection {
$imageValidationSet = (new ValidationSet())
->setRules([
'required',
Rule::notIn(['[]']),
])
->setMessages([
'required' => __('validation.required'),
'not_in' => __('validation.required'),
]);
/** @var ModelServiceInterface $partnerModelService */
$partnerModelService = app(ModelServiceInterface::class);
$partnerModelService->setModelClassName(Partner::class);
//*****************************************************************************************\\
//*** Generate the attributes ***\\
//*****************************************************************************************\\
$attributes = [];
$attributes[] = (new OnOff())
->setLabelText(__('kms/global.active'))
->switchOn()
->mapValueFrom(Attribute::ValueFromModel, 'active');
$attributes[] = (new TextField(__('kms/global.name')))
->mapValueFrom(Attribute::ValueFromModel, 'name');
$attributes[] = (new Documents())
->setLabelText('Afbeelding (alleen van het type .svg)')
->setValidationSet($imageValidationSet)
->setAccept('image/svg+xml')
->setMaxDocuments(1)
->setSubFolder('partners')
->setSmallDragAndDropArea()
->setImageProperties([
(new ImageProperty())->setName('thumb')->setCropMethod(ImageProperty::Resize)->setHeight(100),
(new ImageProperty())->setName('small')->setCropMethod(ImageProperty::Resize)->setHeight(200),
])
->mapValueFrom(Attribute::ValueFromDocuments, 'partners');
// $attributes[] = (new TextArea())
// ->setLabelText('Beschrijving')
// ->enableTinymceEditor()
// ->mapValueFrom(Attribute::ValueFromModel, 'description');
$partnerOptionModels = $partnerModelService->getOptionsForSelectAsTree();
$attributes[] = (new Select())
->setItems($partnerOptionModels->toArray())
->setLabelText(__('kms/partners.parent_partner'))
->setExcludeCurrentModelItem(true)
->setStyleClass('hidden')
->mapValueFrom(Attribute::ValueFromItself, 'parent_id');
// //Build an array with attributes for each current site language
// $languageIndexedAttributes = $this->createAttributesFromExistingAttributeForCurrentSiteLanguages([
//
// (new TextField(__('kms/global.name')))
// ->setValidationSet($nameValidationSet)
// ->setLabelText(__('kms/global.name'))
// ->mapValueFrom(Attribute::ValueFromTranslationModel, 'name'),
// ]);
//Return all attributes as a collection
return collect(array_merge($attributes));
}
/**
* This method will stop the load entities of the kmsSiteSection
*
* @return array
*
*/
public function loadEntities(){
return [];
}
}