Added basic admin page for Label profiles.

This commit is contained in:
Jan Böhmer 2020-04-11 17:34:01 +02:00
parent b23dec0262
commit a8a92b9c5d
20 changed files with 1688 additions and 857 deletions

View file

@ -45,6 +45,8 @@ namespace App\Form\AdminPages;
use App\Entity\Attachments\Attachment;
use App\Entity\Base\AbstractNamedDBElement;
use App\Entity\Base\AbstractStructuralDBElement;
use App\Entity\LabelSystem\LabelOptions;
use App\Entity\LabelSystem\LabelProfile;
use App\Form\AttachmentFormType;
use App\Form\ParameterType;
use App\Form\Type\MasterPictureAttachmentType;
@ -94,36 +96,50 @@ class BaseEntityAdminForm extends AbstractType
'placeholder' => 'part.name.placeholder',
],
'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'edit', $entity),
])
->add('parent', StructuralEntityType::class, [
'class' => get_class($entity),
'required' => false,
'label' => 'parent.label',
'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'move', $entity),
])
->add('not_selectable', CheckboxType::class, [
'required' => false,
'label' => 'entity.edit.not_selectable',
'help' => 'entity.edit.not_selectable.help',
'label_attr' => [
'class' => 'checkbox-custom',
],
'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'edit', $entity),
])
->add('comment', CKEditorType::class, [
'required' => false,
'empty_data' => '',
'label' => 'comment.label',
'attr' => [
'rows' => 4,
],
'help' => 'bbcode.hint',
'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'edit', $entity),
]);
if ($entity instanceof AbstractStructuralDBElement) {
$builder->add(
'parent',
StructuralEntityType::class,
[
'class' => get_class($entity),
'required' => false,
'label' => 'parent.label',
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity),
]
)
->add(
'not_selectable',
CheckboxType::class,
[
'required' => false,
'label' => 'entity.edit.not_selectable',
'help' => 'entity.edit.not_selectable.help',
'label_attr' => [
'class' => 'checkbox-custom',
],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity),
]
);
}
if ($entity instanceof AbstractStructuralDBElement || $entity instanceof LabelProfile) {
$builder->add(
'comment',
CKEditorType::class,
[
'required' => false,
'empty_data' => '',
'label' => 'comment.label',
'attr' => [
'rows' => 4,
],
'help' => 'bbcode.hint',
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity),
]
);
}
$this->additionalFormElements($builder, $options, $entity);
//Attachment section
@ -154,19 +170,25 @@ class BaseEntityAdminForm extends AbstractType
'empty_data' => null,
]);
$builder->add('parameters', CollectionType::class, [
'entry_type' => ParameterType::class,
'allow_add' => $this->security->isGranted($is_new ? 'create' : 'edit', $entity),
'allow_delete' => $this->security->isGranted($is_new ? 'create' : 'edit', $entity),
'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'edit', $entity),
'reindex_enable' => true,
'label' => false,
'by_reference' => false,
'prototype_data' => new $options['parameter_class'](),
'entry_options' => [
'data_class' => $options['parameter_class'],
],
]);
if ($entity instanceof StructuralEntityType) {
$builder->add(
'parameters',
CollectionType::class,
[
'entry_type' => ParameterType::class,
'allow_add' => $this->security->isGranted($is_new ? 'create' : 'edit', $entity),
'allow_delete' => $this->security->isGranted($is_new ? 'create' : 'edit', $entity),
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity),
'reindex_enable' => true,
'label' => false,
'by_reference' => false,
'prototype_data' => new $options['parameter_class'](),
'entry_options' => [
'data_class' => $options['parameter_class'],
],
]
);
}
//Buttons
$builder->add('save', SubmitType::class, [

View file

@ -0,0 +1,42 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2020 Jan Böhmer (https://github.com/jbtronics)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
namespace App\Form\AdminPages;
use App\Entity\Base\AbstractNamedDBElement;
use App\Entity\LabelSystem\LabelProfile;
use App\Form\LabelOptionsType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class LabelProfileAdminForm extends BaseEntityAdminForm
{
protected function additionalFormElements(FormBuilderInterface $builder, array $options, AbstractNamedDBElement $entity): void
{
$builder->add('options', LabelOptionsType::class);
}
public function configureOptions(OptionsResolver $resolver): void
{
parent::configureOptions($resolver);
$resolver->setDefault('data_class', LabelProfile::class);
}
}