File: D:/HostingSpaces/SBogers10/finsteps.komma.pro/app/WebsiteConfig/WebsiteConfigSection.php
<?php
namespace App\WebsiteConfig;
use App\Helpers\KommaHelpers;
use App\Buttons\Kms\ButtonService;
use Illuminate\Database\Eloquent\Model;
use Komma\KMS\Core\Attributes\Attribute;
use Komma\KMS\Core\Attributes\Documents;
use Komma\KMS\Core\Attributes\Models\ImageProperty;
use Komma\KMS\Core\Attributes\MultiSelect;
use Komma\KMS\Core\Attributes\Seperator;
use Komma\KMS\Core\Attributes\TextField;
use Komma\KMS\Core\Attributes\Title;
use Komma\KMS\Core\Attributes\Video;
use Komma\KMS\Core\Sections\Section;
use App\Servicepoints\Kms\ServicepointService;
use App\Servicepoints\Models\Servicepoint;
use App\WebsiteConfig\Model\WebsiteConfig;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Collection;
use Illuminate\Support\MessageBag;
use Komma\KMS\Core\Sections\Tabs\Collections\NoLanguageTabs;
use Komma\KMS\Users\Models\KmsUserRole;
class WebsiteConfigSection extends Section
{
protected $title = "Website";
protected $subTitle = "Configurations";
protected $slug = "websiteconfig";
public $showSave = 'all'; // Options: 'all' | 'admin' (SuperAdmin only) | 'none' (or anything else what isn't all or admin)
public $showDelete = 'admin';
public $showCreate = 'admin';
/**
* PageSection constructor.
* @param $slug
*/
// function __construct(Kms $kms, PageRepository $repository)
function __construct($slug)
{
$tabs = new NoLanguageTabs();
parent::__construct($tabs, $slug);
$this->submitButtonLabel = __('KMS::kms/global.save');
}
/**
* Generates the attributes for this section. They all must extend the Komma\KMS\Core\Attributes\Attribute class
*
* @param Model $currentModel
* @return \Illuminate\Support\Collection A collection of SectionTabItems
*/
protected function generateAttributes(Model $currentModel = null): Collection
{
//*****************************************************************************************\\
//*** Generate the attributes ***\\
//*****************************************************************************************\\
$buttonsService = \App::make(ButtonService::class);
$buttonModels = $buttonsService->getOptionsForSelect();
$attributes = [];
$attributes[] = (new Title('Bedrijfsgegevens'))
->setMinimumUserRole(KmsUserRole::Admin);
$attributes[] = (new TextField('Url'))
->mapValueFrom(Attribute::ValueFromModel, 'company_url')
->setMinimumUserRole(KmsUserRole::Admin);
$attributes[] = (new TextField('Bedrijfsnaam'))
->mapValueFrom(Attribute::ValueFromModel, 'company_name')
->setMinimumUserRole(KmsUserRole::Admin);
$attributes[] = (new TextField('Adres'))
->mapValueFrom(Attribute::ValueFromModel, 'company_address')
->setMinimumUserRole(KmsUserRole::Admin);
$attributes[] = (new TextField('Postcode'))
->mapValueFrom(Attribute::ValueFromModel, 'company_zip')
->setMinimumUserRole(KmsUserRole::Admin);
$attributes[] = (new TextField('Stad'))
->mapValueFrom(Attribute::ValueFromModel, 'company_city')
->setMinimumUserRole(KmsUserRole::Admin);
$attributes[] = (new TextField('Land'))
->mapValueFrom(Attribute::ValueFromModel, 'company_country')
->setMinimumUserRole(KmsUserRole::Admin);
$attributes[] = (new TextField('KVK'))
->mapValueFrom(Attribute::ValueFromModel, 'company_kvk')
->setMinimumUserRole(KmsUserRole::Admin);
$attributes[] = (new TextField('E-mail'))
->mapValueFrom(Attribute::ValueFromModel, 'company_email')
->setMinimumUserRole(KmsUserRole::Admin);
$attributes[] = (new TextField('Telefoon link'))
->mapValueFrom(Attribute::ValueFromModel, 'company_phone_call')
->setMinimumUserRole(KmsUserRole::Admin);
$attributes[] = (new TextField('Telefoon weergave'))
->mapValueFrom(Attribute::ValueFromModel, 'company_phone_display')
->setMinimumUserRole(KmsUserRole::Admin);
// Google Maps
// ---------------------------------------
$attributes[] = (new Seperator())
->setMinimumUserRole(KmsUserRole::Admin);
$attributes[] = (new Title('Google Maps'))
->setMinimumUserRole(KmsUserRole::Admin);
$attributes[] = (new TextField('Latitude'))
->setPlaceholderText('Ex. 51.257929')
->mapValueFrom(Attribute::ValueFromModel, 'google_maps_lat')
->setMinimumUserRole(KmsUserRole::Admin);
$attributes[] = (new TextField('Longitude'))
->setPlaceholderText('Ex. 5.595330')
->mapValueFrom(Attribute::ValueFromModel, 'google_maps_long')
->setMinimumUserRole(KmsUserRole::Admin);
// Social Media
// ---------------------------------------
$attributes[] = (new Seperator())
->setMinimumUserRole(KmsUserRole::Admin);
$attributes[] = (new Title('Sociale media'))
->setMinimumUserRole(KmsUserRole::Admin);
$attributes[] = (new TextField('Facebook'))
->mapValueFrom(Attribute::ValueFromModel, 'company_social_facebook')
->setMinimumUserRole(KmsUserRole::Admin);
$attributes[] = (new TextField('Linkedin'))
->mapValueFrom(Attribute::ValueFromModel, 'company_social_linkedin')
->setMinimumUserRole(KmsUserRole::Admin);
$attributes[] = (new TextField('Instagram'))
->mapValueFrom(Attribute::ValueFromModel, 'company_social_instagram')
->setMinimumUserRole(KmsUserRole::Admin);
$attributes[] = (new TextField('Twitter'))
->mapValueFrom(Attribute::ValueFromModel, 'company_social_twitter')
->setMinimumUserRole(KmsUserRole::Admin);
// ServicePoint
// ---------------------------------------
$servicePointService = \App::make(ServicepointService::class);
$servicePointOptions = $servicePointService->getOptionsForSelect(false, true);
$attributes[] = (new Seperator())
->setMinimumUserRole(KmsUserRole::Admin);
$attributes[] = (new Title(__('kms/global.defaultServicePoint')))
->setMinimumUserRole(KmsUserRole::SuperAdmin);
$attributes[] = (new TextField(__('kms/global.servicePointHeading')))
->mapValueFrom(Attribute::ValueFromModel, 'global_servicePoint_heading')
->setMinimumUserRole(KmsUserRole::SuperAdmin);
$attributes[] = (new MultiSelect())
->setItems($servicePointOptions->toArray())
->setLabelText(__('Contactpersoon'))
->setMaxItemsToSelect(1)
->canBeLinkedWith(Servicepoint::class)
->mapValueFrom(Attribute::ValueFromModel, 'global_servicePoint_id')
->setMinimumUserRole(KmsUserRole::SuperAdmin);
$attributes[] = (new MultiSelect())
->setItems($buttonModels->toArray())
->setMaxItemsToSelect(1)
->setLabelText(__('kms/global.servicePointButton'))
->mapValueFrom(Attribute::ValueFromModel, 'global_servicePoint_button_id')
->setMinimumUserRole(KmsUserRole::SuperAdmin);
// Callout Bar
// ---------------------------------------
$attributes[] = (new Seperator())
->setMinimumUserRole(KmsUserRole::Admin);
$attributes[] = (new Title(__('kms/global.defaultCalloutBar')))
->setMinimumUserRole(KmsUserRole::SuperAdmin);
$attributes[] = (new TextField(__('kms/global.calloutBarHeading')))
->mapValueFrom(Attribute::ValueFromModel, 'global_CTA_heading')
->setMinimumUserRole(KmsUserRole::SuperAdmin);
$attributes[] = (new MultiSelect())
->setItems($buttonModels->toArray())
->setMaxItemsToSelect(1)
->setLabelText(__('kms/global.calloutBarButton'))
->mapValueFrom(Attribute::ValueFromModel, 'global_CTA_button_id')
->setMinimumUserRole(KmsUserRole::SuperAdmin);
// Logo's
// ---------------------------------------
$attributes[] = (new Seperator())
->setMinimumUserRole(KmsUserRole::SuperAdmin);
$attributes[] = (new Title(__('KMS::kms/global.logos')))
->setMinimumUserRole(KmsUserRole::SuperAdmin);
$attributes[] = (new Documents())
->setLabelText(__('KMS::kms/global.logo_on_light'))
->onlyAllowImages()
->setSmallDragAndDropArea()
->setMaxDocuments(1)
->setSubFolder('home')
->setImageProperties([
(new ImageProperty())->setName('small')->setCropMethod(ImageProperty::Fit)->setWidth(147)->setHeight(48),
])
->mapValueFrom(Attribute::ValueFromDocuments, 'logo_on_light')
->setMinimumUserRole(KmsUserRole::SuperAdmin);
$attributes[] = (new Documents())
->setLabelText(__('KMS::kms/global.logo_on_dark'))
->onlyAllowImages()
->setSmallDragAndDropArea()
->setMaxDocuments(1)
->setSubFolder('home')
->setImageProperties([
(new ImageProperty())->setName('small')->setCropMethod(ImageProperty::Fit)->setWidth(152)->setHeight(50),
])
->mapValueFrom(Attribute::ValueFromDocuments, 'logo_on_dark')
->setMinimumUserRole(KmsUserRole::SuperAdmin);
// Hero
// ---------------------------------------
$attributes[] = (new Seperator())
->setMinimumUserRole(KmsUserRole::SuperAdmin);
$attributes[] = (new Title(__('kms/global.homeHero')))
->setMinimumUserRole(KmsUserRole::SuperAdmin);
$attributes[] = (new Documents())
->setLabelText(__('kms/global.homeHeroImages'))
->onlyAllowImages()
->setSmallDragAndDropArea()
->setMaxDocuments(5)
->setSubFolder('home')
->setImageProperties([
(new ImageProperty())->setName('large')->setCropMethod(ImageProperty::Fit)->setWidth(1152)->setHeight(640),
(new ImageProperty())->setName('medium')->setCropMethod(ImageProperty::Fit)->setWidth(920)->setHeight(460),
(new ImageProperty())->setName('small')->setCropMethod(ImageProperty::Fit)->setWidth(837)->setHeight(465),
])
->mapValueFrom(Attribute::ValueFromDocuments, 'home_hero_images')
->setMinimumUserRole(KmsUserRole::SuperAdmin);
$attributes[] = (new TextField(__('kms/global.homeHeroTitle')))
->mapValueFrom(Attribute::ValueFromTranslationModel, 'home_hero_title')
->setMinimumUserRole(KmsUserRole::SuperAdmin);
// $attributes[] = (new Title(__('kms/global.homeHeroVideoHeader')))
// ->setMinimumUserRole(KmsUserRole::SuperAdmin);
$attributes[] = (new Video(__('kms/global.homeHeroVideo')))
->mapValueFrom(Attribute::ValueFromModel, 'home_hero_video')
->setMinimumUserRole(KmsUserRole::SuperAdmin);
$attributes[] = (new Seperator())
->setMinimumUserRole(KmsUserRole::SuperAdmin);
//Return all attributes as a collection
$attributes = collect(array_merge($attributes));
return $attributes;
}
}