2019-03-28 19:24:34 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* part-db version 0.1
|
|
|
|
* Copyright (C) 2005 Christoph Lechner
|
|
|
|
* http://www.cl-projects.de/
|
|
|
|
*
|
|
|
|
* part-db version 0.2+
|
|
|
|
* Copyright (C) 2009 K. Jacobs and others (see authors.php)
|
|
|
|
* http://code.google.com/p/part-db/
|
|
|
|
*
|
|
|
|
* Part-DB Version 0.4+
|
|
|
|
* Copyright (C) 2016 - 2019 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 General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2019-08-12 22:41:58 +02:00
|
|
|
namespace App\Form\AdminPages;
|
2019-03-28 19:24:34 +01:00
|
|
|
|
|
|
|
|
2019-09-24 18:28:35 +02:00
|
|
|
use App\Entity\Attachments\Attachment;
|
|
|
|
use App\Entity\Attachments\FootprintAttachment;
|
|
|
|
use App\Entity\Attachments\PartAttachment;
|
2019-08-12 18:04:53 +02:00
|
|
|
use App\Entity\Base\NamedDBElement;
|
|
|
|
use App\Entity\Base\StructuralDBElement;
|
2019-09-24 18:28:35 +02:00
|
|
|
use App\Form\AttachmentFormType;
|
2019-08-13 23:04:06 +02:00
|
|
|
use App\Form\Type\StructuralEntityType;
|
2019-03-28 19:24:34 +01:00
|
|
|
use FOS\CKEditorBundle\Form\Type\CKEditorType;
|
|
|
|
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
2019-08-12 23:45:21 +02:00
|
|
|
use Symfony\Component\DependencyInjection\ParameterBag\ContainerBagInterface;
|
|
|
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
2019-03-28 19:24:34 +01:00
|
|
|
use Symfony\Component\Form\AbstractType;
|
2019-08-12 21:47:25 +02:00
|
|
|
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
2019-09-24 18:28:35 +02:00
|
|
|
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
|
2019-03-28 19:24:34 +01:00
|
|
|
use Symfony\Component\Form\Extension\Core\Type\ResetType;
|
|
|
|
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
|
|
|
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
|
|
|
use Symfony\Component\Form\FormBuilderInterface;
|
2019-09-24 18:28:35 +02:00
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
2019-03-28 19:24:34 +01:00
|
|
|
use Symfony\Component\Security\Core\Security;
|
2019-09-04 15:53:18 +02:00
|
|
|
use Symfony\Component\Translation\Reader\TranslationReader;
|
|
|
|
use Symfony\Contracts\Translation\TranslatorInterface;
|
2019-03-28 19:24:34 +01:00
|
|
|
|
|
|
|
class BaseEntityAdminForm extends AbstractType
|
|
|
|
{
|
|
|
|
|
|
|
|
protected $security;
|
2019-08-12 23:45:21 +02:00
|
|
|
protected $params;
|
2019-09-04 15:53:18 +02:00
|
|
|
protected $trans;
|
2019-03-28 19:24:34 +01:00
|
|
|
|
2019-09-04 15:53:18 +02:00
|
|
|
public function __construct(Security $security, ParameterBagInterface $params, TranslatorInterface $trans)
|
2019-03-28 19:24:34 +01:00
|
|
|
{
|
|
|
|
$this->security = $security;
|
2019-08-12 23:45:21 +02:00
|
|
|
$this->params = $params;
|
2019-09-04 15:53:18 +02:00
|
|
|
$this->trans = $trans;
|
2019-03-28 19:24:34 +01:00
|
|
|
}
|
|
|
|
|
2019-09-24 18:28:35 +02:00
|
|
|
public function configureOptions(OptionsResolver $resolver)
|
|
|
|
{
|
|
|
|
parent::configureOptions($resolver); // TODO: Change the autogenerated stub
|
|
|
|
$resolver->setRequired('attachment_class');
|
|
|
|
}
|
2019-03-28 19:24:34 +01:00
|
|
|
|
|
|
|
public function buildForm(FormBuilderInterface $builder, array $options)
|
|
|
|
{
|
2019-04-13 18:43:23 +02:00
|
|
|
/** @var StructuralDBElement $entity */
|
2019-03-28 19:24:34 +01:00
|
|
|
$entity = $options['data'];
|
2019-04-13 18:43:23 +02:00
|
|
|
$is_new = $entity->getID() === null;
|
2019-03-28 19:24:34 +01:00
|
|
|
|
|
|
|
$builder
|
2019-09-04 15:53:18 +02:00
|
|
|
->add('name', TextType::class, ['empty_data' => '', 'label' => $this->trans->trans('name.label'),
|
|
|
|
'attr' => ['placeholder' => $this->trans->trans('part.name.placeholder')],
|
2019-04-13 19:03:45 +02:00
|
|
|
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ])
|
2019-03-28 19:24:34 +01:00
|
|
|
|
2019-08-13 23:04:06 +02:00
|
|
|
->add('parent', StructuralEntityType::class, ['class' => get_class($entity),
|
2019-09-04 15:53:18 +02:00
|
|
|
'required' => false, 'label' => $this->trans->trans('parent.label'),
|
2019-04-13 19:03:45 +02:00
|
|
|
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity), ])
|
2019-03-28 19:24:34 +01:00
|
|
|
|
2019-08-12 21:47:25 +02:00
|
|
|
->add('not_selectable', CheckboxType::class, ['required' => false,
|
2019-09-04 15:53:18 +02:00
|
|
|
'label' => $this->trans->trans('entity.edit.not_selectable'),
|
|
|
|
'help' => $this->trans->trans('entity.edit.not_selectable.help'),
|
|
|
|
'label_attr' => ['class' => 'checkbox-custom'],
|
2019-08-12 21:47:25 +02:00
|
|
|
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity) ])
|
|
|
|
|
2019-08-12 23:45:21 +02:00
|
|
|
->add('comment', CKEditorType::class, ['required' => false, 'empty_data' => '',
|
2019-09-04 15:53:18 +02:00
|
|
|
'label' => $this->trans->trans('comment.label'),
|
|
|
|
'attr' => ['rows' => 4], 'help' => $this->trans->trans('bbcode.hint'),
|
2019-04-26 18:05:43 +02:00
|
|
|
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity)]);
|
|
|
|
|
|
|
|
$this->additionalFormElements($builder, $options, $entity);
|
2019-03-28 19:24:34 +01:00
|
|
|
|
2019-09-24 18:28:35 +02:00
|
|
|
//Attachment section
|
|
|
|
$builder->add('attachments', CollectionType::class, [
|
|
|
|
'entry_type' => AttachmentFormType::class,
|
|
|
|
'allow_add' => true,
|
|
|
|
'allow_delete' => true,
|
|
|
|
'label' => false,
|
2019-09-24 18:41:53 +02:00
|
|
|
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity),
|
2019-09-24 18:28:35 +02:00
|
|
|
'entry_options' => [
|
|
|
|
'data_class' => $options['attachment_class'],
|
|
|
|
],
|
|
|
|
'by_reference' => false
|
|
|
|
]);
|
|
|
|
|
2019-03-28 19:24:34 +01:00
|
|
|
//Buttons
|
2019-09-04 15:53:18 +02:00
|
|
|
$builder->add('save', SubmitType::class, [
|
|
|
|
'label' => $is_new ? $this->trans->trans('entity.create') : $this->trans->trans('entity.edit.save'),
|
2019-04-13 19:03:45 +02:00
|
|
|
'attr' => ['class' => $is_new ? 'btn-success' : ''],
|
|
|
|
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity)])
|
|
|
|
->add('reset', ResetType::class, ['label' => 'entity.edit.reset',
|
|
|
|
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity)]);
|
2019-03-28 19:24:34 +01:00
|
|
|
}
|
2019-04-26 18:05:43 +02:00
|
|
|
|
|
|
|
protected function additionalFormElements(FormBuilderInterface $builder, array $options, NamedDBElement $entity)
|
|
|
|
{
|
|
|
|
//Empty for Base
|
|
|
|
}
|
2019-03-28 19:24:34 +01:00
|
|
|
}
|