File: D:/HostingSpaces/SBogers95/rentman.io/app/Komma/CustomerStories/Kms/CustomerStorySection.php
<?php
/**
* @author Komma <info@komma.pro>
* @copyright (c) 2012-2016, Komma
*/
namespace App\Komma\CustomerStories\Kms;
//The new object oriented attributes
use App\Komma\Dynamic\ComponentType\ComponentTypes;
use App\Komma\Kms\Core\Attributes\Attribute;
use App\Komma\Kms\Core\Attributes\AutocompleteInput;
use App\Komma\Kms\Core\Attributes\ComponentArea;
use App\Komma\Kms\Core\Attributes\Documents;
use App\Komma\Kms\Core\Attributes\Link;
use App\Komma\Kms\Core\Attributes\Models\ImageProperty;
use App\Komma\Kms\Core\Attributes\OnOff;
use App\Komma\Kms\Core\Attributes\Select;
use App\Komma\Kms\Core\Attributes\Seperator;
use App\Komma\Kms\Core\Attributes\TextArea;
use App\Komma\Kms\Core\Attributes\TextField;
use App\Komma\Kms\Core\Attributes\Title;
use App\Komma\Kms\Core\Sections\CurrentSiteLanguagesTabsDirector;
use App\Komma\Kms\Core\Sections\Section;
use App\Komma\Kms\Core\Sections\SectionTabGroups;
use App\Komma\Kms\Core\Sections\SectionTabItem;
use App\Komma\Kms\Core\Sections\SectionTabsBuilder;
use App\Komma\Kms\Core\ValidationSet;
use App\Komma\Products\Kms\ProductService;
use App\Komma\Routes\RouteService;
use App\Komma\Sites\SiteServiceInterface;
use Illuminate\Database\Eloquent\Collection;
class CustomerStorySection extends Section
{
protected $slug = 'customerstories';
protected $hasRoutes = true;
/**
* CustomerStorySection constructor.
* @param CustomerStoryService $sectionService
* @param RouteService $routeService
* @param SiteServiceInterface $siteService
*/
// function __construct(Kms $kms, CustomerStoryRepository $repository)
public function __construct(CustomerStoryService $sectionService, RouteService $routeService, SiteServiceInterface $siteService)
{
$sectionTabDirector = new CurrentSiteLanguagesTabsDirector(new SectionTabsBuilder()); //Can make tabs for us. also see KmsSection::__construct
parent::__construct($sectionService, $routeService, $siteService, $sectionTabDirector);
}
/**
* 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 CustomerStoryRepository::saveModel()
* @return Collection A collection of SectionTabItems
* @throws \Exception
*/
protected function generateAttributes(): Collection
{
$fixedAttributeTabItems = $this->generateFixedAttributes();
$tabItems = $fixedAttributeTabItems;
$languageIndexedAttributes = $this->createAttributesFromExistingAttributeForCurrentSiteLanguages([
(new Seperator()),
(new Title(__('kms/global.componentTitle'))),
(new ComponentArea())
->setSubFolder('customer_story_area')
// ->disableBackgroundOption()
->setComponentTypes([
ComponentTypes::VIDEO,
ComponentTypes::IMAGE,
ComponentTypes::TEXT,
ComponentTypes::QUOTE,
ComponentTypes::TEXT_IMAGE,
])
->mapValueFrom(Attribute::ValueFromComponents, 'customer_story_area'),
]);
foreach ($languageIndexedAttributes as $attribute) {
$tabItems->push(new SectionTabItem($attribute, SectionTabGroups::Languages));
}
return $tabItems;
}
/**
* Generate fixed attributes
*
* @return Collection
*/
private function generateFixedAttributes(): Collection
{
/** @var CustomerStoryService $customerStoryService */
$customerStoryService = $this->getSectionService();
//*****************************************************************************************\\
//*** Define attribute validation sets ***\\
//*****************************************************************************************\\
$numberValidationSet = (new ValidationSet())
->setRules('nullable|numeric')
->setMessages(['numeric' => __('validation.numeric'), 'nullable' => '']);
$urlValidationSet = (new ValidationSet())
->setRules('nullable|url')
->setMessages(['url' => __('validation.url'), 'nullable' => '']);
//*****************************************************************************************\\
//*** Generate the attributes ***\\
//*****************************************************************************************\\
$attributes = [];
// $attributes[] = (new Video('Youtube'));
$attributes[] = (new TextField(__('kms/global.name')))
->setPlaceholderText(__('kms/global.enterName'))
->mapValueFrom(Attribute::ValueFromModel, 'name');
$attributes[] = (new TextField(__('kms/customerstories.amountOfEmployees')))
->setPlaceholderText(__('kms/customerstories.enterAmountOfEmployees'))
->mapValueFrom(Attribute::ValueFromModel, 'amount_of_employees')
->setValidationSet($numberValidationSet);
$customerStoryOptionModels = $customerStoryService->getOptionsForSelect(true);
$attributes[] = (new Select())
->setItems($customerStoryOptionModels->toArray())
->setLabelText(__('kms/customerstories.parent_page'))
->setExcludeCurrentModelItem(true)
->setStyleClass('hidden')
->mapValueFrom(Attribute::ValueFromModel, 'parent_id');
$attributes[] = (new Seperator());
$attributes[] = (new Title(__('kms/customerstories.site')));
$attributes[] = (new TextField(__('kms/customerstories.siteName')))
->setPlaceholderText(__('kms/customerstories.enterSiteName'))
->mapValueFrom(Attribute::ValueFromModel, 'site_name');
$attributes[] = (new TextField(__('kms/customerstories.siteUrl')))
->setPlaceholderText(__('kms/customerstories.enterSiteUrl'))
->mapValueFrom(Attribute::ValueFromModel, 'site_url')
->setValidationSet($urlValidationSet);
$attributes[] = (new Seperator());
$attributes[] = (new Title(__('kms/customerstories.images')));
$attributes[] = (new Documents())
->setLabelText(__('kms/customerstories.logo'))
->onlyAllowImages()
->setSmallDragAndDropArea()
->setMaxDocuments(1)
->setSubFolder('customerStoryLogos')
->setImageProperties([
(new ImageProperty())->setName('medium')->setCropMethod(ImageProperty::Resize)->setWidth(450),
(new ImageProperty())->setName('small')->setCropMethod(ImageProperty::Resize)->setWidth(220),
(new ImageProperty())->setName('thumb')->setCropMethod(ImageProperty::Fit)->setWidth(128),
]
)
->mapValueFrom(Attribute::ValueFromDocuments, 'logo');
$attributes[] = (new Documents())
->setLabelText(__('kms/customerstories.impression'))
->onlyAllowImages()
->setSmallDragAndDropArea()
->setMaxDocuments(1)
->setSubFolder('customerStoryImpression')
->mapValueFrom(Attribute::ValueFromDocuments, 'impression');
$attributes[] = (new OnOff())
->setLabelText(__('kms/customerstories.blur'))
->switchOn()
->mapValueFrom(Attribute::ValueFromModel, 'blur_image');
$attributes[] = (new Seperator());
$attributes[] = (new Title(__('kms/customerstories.features')));
$productService = \App::make(ProductService::class);
$attributes[] = (new AutocompleteInput())
->setLabelText(__('kms/customerstories.features'))
->fillWith(ProductService::class.'@getOptionsForSelect')
->mapValueFrom(Attribute::ValueFromModelHasManyRelation, 'products|id');
//Build an array with attributes for each current site language
$languageIndexedAttributes = $this->createAttributesFromExistingAttributeForCurrentSiteLanguages([
(new TextField('Last Modified'))
->setStyleClass('is-disabled')
->mapValueFrom(Attribute::ValueFromItself, 'last_modified'),
(new OnOff())
->setLabelText(__('kms/global.active'))
// ->switchOn()
->mapValueFrom(Attribute::ValueFromTranslationModel, 'active'),
(new OnOff())
->setLabelText(__('kms/global.preview'))
->setExplanation(__('kms/global.previewExplanation'))
->mapValueFrom(Attribute::ValueFromTranslationModel, 'preview'),
(new Link())
->setLabelText(__('kms/global.link'))
->setExplanation(__('kms/global.linkExplanation'))
->mapValueFrom(Attribute::ValueFromItself, 'link'),
(new Documents())
->setLabelText('Social Media Image')
->onlyAllowImages()
->setSmallDragAndDropArea()
->setMaxDocuments(1)
->setSubFolder('customerStories')
->mapValueFrom(Attribute::ValueFromDocuments, 'customerStoryTranslationSocial'),
(new Seperator()),
(new Title(__('kms/customerstories.heading'))),
(new TextField(__('kms/customerstories.title')))
->setPlaceholderText(__('kms/customerstories.enterTitle'))
->mapValueFrom(Attribute::ValueFromTranslationModel, 'title'),
(new TextArea())
->setLabelText(__('kms/customerstories.description'))
->setPlaceholderText(__('kms/customerstories.enterDescription'))
->mapValueFrom(Attribute::ValueFromTranslationModel, 'description'),
(new TextField(__('kms/customerstories.industry')))
->setPlaceholderText(__('kms/customerstories.enterIndustry'))
->mapValueFrom(Attribute::ValueFromTranslationModel, 'industry'),
(new Seperator()),
(new Title(__('kms/products.seo'))),
(new TextField(__('kms/global.metaTitle')))
->setPlaceholderText(__('kms/global.enterTitle'))
->mapValueFrom(Attribute::ValueFromTranslationModel, 'meta_title')
->setContentCounterAmount(60),
(new TextArea())
->setLabelText(__('kms/global.metaDescription'))
->setPlaceholderText(__('kms/global.enterMetaDescription'))
->mapValueFrom(Attribute::ValueFromTranslationModel, 'meta_description')
->setContentCounterAmount(155),
]);
//****************************************************************************************************************************************\\
//*** Put the all attributes in a SectionTabItem so we can track for which tab they are. And then put SectionTabItems in a Collection ***\\
//****************************************************************************************************************************************\\
$tabItems = new Collection();
foreach ($attributes as $attribute) {
$tabItems->push(new SectionTabItem($attribute, SectionTabGroups::General));
}
foreach ($languageIndexedAttributes as $attribute) {
$tabItems->push(new SectionTabItem($attribute, SectionTabGroups::Languages));
}
return $tabItems;
}
/**
* This method will stop the load entities of the kmsSiteSection
*
* @return array
*/
public function loadEntities()
{
return [];
}
}