File: D:/HostingSpaces/SBogers10/beat-the-barn.komma.nl/app/Meals/Kms/MealSection.php
<?php
namespace App\Meals\Kms;
use App\Meals\Models\Meal;
use Illuminate\Database\Eloquent\Model;
use Komma\KMS\Core\Attributes\Documents;
use Komma\KMS\Core\Attributes\Attribute;
use Komma\KMS\Core\Attributes\Models\ImageProperty;
use Komma\KMS\Core\Attributes\Numeric;
use Komma\KMS\Core\Attributes\OnOff;
use Komma\KMS\Core\Attributes\Select;
use Komma\KMS\Core\Attributes\TextArea;
use Komma\KMS\Core\Attributes\TextField;
use Komma\KMS\Core\ModelServiceInterface;
use Komma\KMS\Core\Sections\Section;
final class MealSection extends Section
{
public function defineAttributesAndTabs(Model $currentModel = null): void
{
/** @var ModelServiceInterface $mealModelService */
$mealModelService = app(ModelServiceInterface::class);
$mealModelService->setModelClassName(Meal::class);
$this->tabs->makeTab()->addItems([
(new Select())
->setItems($mealModelService->getOptionsForSelectAsTree()->toArray())
->setLabelText(__('KMS::meals.parent_id'))
->enableExcludeCurrentModelItem()
->setStyleClass('hidden')
->mapValueFrom(Attribute::ValueFromItself, 'parent_id'),
(new OnOff())
->setReference('active')
->setLabelText(__('KMS::global.active'))
->switchOn(),
(new Documents())
->setReference('meals')
->setLabelText(__('KMS::global.images'))
->onlyAllowImages()
->setSmallDragAndDropArea()
->setMaxDocuments(1)
->setSubFolder('meals')
->setImageProperties([
(new ImageProperty())->setName('thumb')->setCropMethod(ImageProperty::Fit)->setWidth(100)->setHeight(100),
(new ImageProperty())->setName('small')->setCropMethod(ImageProperty::Fit)->setWidth(200)->setHeight(200),
(new ImageProperty())->setName('medium')->setCropMethod(ImageProperty::Fit)->setWidth(300)->setHeight(300),
]),
(new TextField())
->setLabelText(__('KMS::global.name'))
->mapValueFrom(Attribute::ValueFromTranslationModel, 'name'),
(new TextArea())
->setLabelText(__('KMS::global.description'))
->setPlaceholderText(__('KMS::global.enterDescription'))
->mapValueFrom(Attribute::ValueFromTranslationModel, 'description'),
(new Numeric())
->setLabelText('Prijs')
->setReference('price')
->setPrefix('€')
->setFractionLength(2)
->setFractionMax(99)
->setFractionZeroPadding()
->setSuffix('p.p.'),
]);
}
}