File: D:/HostingSpaces/SBogers10/reiskick.komma.nl/app/Journeys/Kms/JourneySection.php
<?php
namespace App\Journeys\Kms;
use App\Components\ComponentTypes;
use App\Countries\Kms\CountryModelService;
use App\Journeys\Models\Journey;
use App\Pages\Models\Page;
use App\Sidebars\Models\Sidebar;
use App\ToDos\Models\ToDo;
use Illuminate\Database\Eloquent\Model;
use Komma\KMS\Core\Attributes\Attribute;
use Komma\KMS\Core\Attributes\ComponentArea;
use Komma\KMS\Core\Attributes\DatePicker;
use Komma\KMS\Core\Attributes\Documents;
use Komma\KMS\Core\Attributes\Link;
use Komma\KMS\Core\Attributes\Models\ImageProperty;
use Komma\KMS\Core\Attributes\Models\SelectOption;
use Komma\KMS\Core\Attributes\MultiSelect;
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\ModelServiceInterface;
use Komma\KMS\Core\Sections\Section;
use Komma\KMS\Users\Models\KmsUserRole;
final class JourneySection extends Section
{
/**
* Define the attributes and tabs for this section.
*
* @param Model $currentModel
*/
public function defineAttributesAndTabs(Model $currentModel = null): void
{
/** @var ModelServiceInterface $pageModelService */
$modelService = app()->make(ModelServiceInterface::class);
$modelService->setModelClassName(Journey::class);
$optionModels = $modelService->getOptionsForSelectAsTree();
/** @var ModelServiceInterface $sidebarService */
$sidebarService = app()->make(ModelServiceInterface::class);
$sidebarService->setModelClassName(Sidebar::class);
/** @var CountryModelService $countryService */
$countryService = app()->make(CountryModelService::class);
$journeyPageRoute = Page::where('code_name', 'journeys')
->with('translation', 'translation.route')
->has('translation')
->has('translation.route')
->first();
if($currentModel != null && $journeyPageRoute != null && isset($currentModel->translation)) $journeyRoute = $journeyPageRoute->translation->route->alias . '/' . $currentModel->translation->slug;
else $journeyRoute = '';
$this->tabs->makeTab()->addItems([
(new OnOff())
->setReference('active')
->setLabelText(__('KMS::global.active'))
->switchOn(),
(new MultiSelect())
->setItems($countryService->getOptionsForSelect()->toArray())
->setLabelText('Land(en)')
->mapValueFrom(Attribute::ValueFromModelHasManyRelation, 'countries|id'),
// (new Seperator()),
(new Documents())
->setReference('journeys_main')
->setLabelText('Overzicht foto')
->onlyAllowImages()
->setSmallDragAndDropArea()
->setMaxDocuments(1)
->setSubFolder('journeys'),
(new Select())
->setItems($optionModels->toArray())
->setLabelText(__('KMS::pages.parent_page'))
->enableExcludeCurrentModelItem()
->setMinimumUserRole(KmsUserRole::SuperAdmin)
->mapValueFrom(Attribute::ValueFromItself, 'parent_id'),
(new Seperator()),
(new Title())->setLabelText('Detail pagina'),
(new Documents())
->setReference('heading')
->setLabelText('Hoofdfoto')
->onlyAllowImages()
->setSmallDragAndDropArea()
->setSubFolder('journey_heading')
->setMaxDocuments(1)
->setImageProperties([
(new ImageProperty())->setName('large')->setCropMethod(ImageProperty::Resize)->setWidth(2200),
(new ImageProperty())->setName('medium')->setCropMethod(ImageProperty::Resize)->setWidth(1400),
(new ImageProperty())->setName('small')->setCropMethod(ImageProperty::Resize)->setWidth(500),
]),
(new OnOff())
->setReference('header_on_dark')
->setLabelText('Header in het wit'),
(new OnOff())
->setReference('align_right')
->setLabelText('Titel rechts uitlijnen'),
(new Select())
->setReference('sidebar_id')
->setItems($sidebarService->getOptionsForSelect()->toArray())
->setLabelText('Sidebar'),
// (new Documents())
// ->setReference('journeys_bg')
// ->setLabelText('Slider achtergrond foto')
// ->onlyAllowImages()
// ->setSmallDragAndDropArea()
// ->setMaxDocuments(1)
// ->setSubFolder('journeys'),
]);
$this->tabs->makeLanguageTabTemplate()->addItems([
(new TextField())
->setReference('name')
->setLabelText(__('KMS::global.title'))
->setRules('required'),
(new Link())
->setLabelText('Url')
->setLinkText($journeyRoute)
->setLink($journeyRoute),
(new Seperator()),
(new Title())->setLabelText('Seo'),
(new TextField())
->setReference('meta_title')
->setLabelText(__('KMS::global.metaTitle')),
(new TextArea())
->setLabelText(__('KMS::global.metaDescription'))
->setReference('meta_description'),
]);
if(isset($currentModel) && $currentModel->exists) {
$this->tabs->getLanguageTabTemplate()->addItems([
(new ComponentArea())
->setReference('journey_components')
->setSubFolder('journey_component_data')
->setComponentTypes(array_merge(ComponentTypes::getDefaultSet(), [
ComponentTypes::MUST_DOS,
ComponentTypes::TO_DOS,
ComponentTypes::HOTELS,
ComponentTypes::OVERNIGHTS,
])),
]);
}
}
}