Completed
Push — master ( 97cb91...eb1d8f )
by Jan
04:48
created

BaseEntityAdminForm::configureOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 *
4
 * part-db version 0.1
5
 * Copyright (C) 2005 Christoph Lechner
6
 * http://www.cl-projects.de/
7
 *
8
 * part-db version 0.2+
9
 * Copyright (C) 2009 K. Jacobs and others (see authors.php)
10
 * http://code.google.com/p/part-db/
11
 *
12
 * Part-DB Version 0.4+
13
 * Copyright (C) 2016 - 2019 Jan Böhmer
14
 * https://github.com/jbtronics
15
 *
16
 * This program is free software; you can redistribute it and/or
17
 * modify it under the terms of the GNU General Public License
18
 * as published by the Free Software Foundation; either version 2
19
 * of the License, or (at your option) any later version.
20
 *
21
 * This program is distributed in the hope that it will be useful,
22
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
 * GNU General Public License for more details.
25
 *
26
 * You should have received a copy of the GNU General Public License
27
 * along with this program; if not, write to the Free Software
28
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
29
 *
30
 */
31
32
namespace App\Form\AdminPages;
33
34
35
use App\Entity\Attachments\Attachment;
36
use App\Entity\Attachments\FootprintAttachment;
37
use App\Entity\Attachments\PartAttachment;
38
use App\Entity\Base\NamedDBElement;
39
use App\Entity\Base\StructuralDBElement;
40
use App\Form\AttachmentFormType;
41
use App\Form\Type\StructuralEntityType;
42
use FOS\CKEditorBundle\Form\Type\CKEditorType;
43
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
44
use Symfony\Component\DependencyInjection\ParameterBag\ContainerBagInterface;
45
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
46
use Symfony\Component\Form\AbstractType;
47
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
48
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
49
use Symfony\Component\Form\Extension\Core\Type\ResetType;
50
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
51
use Symfony\Component\Form\Extension\Core\Type\TextType;
52
use Symfony\Component\Form\FormBuilderInterface;
53
use Symfony\Component\OptionsResolver\OptionsResolver;
54
use Symfony\Component\Security\Core\Security;
55
use Symfony\Component\Translation\Reader\TranslationReader;
56
use Symfony\Contracts\Translation\TranslatorInterface;
57
58
class BaseEntityAdminForm extends AbstractType
59
{
60
61
    protected $security;
62
    protected $params;
63
    protected $trans;
64
65
    public function __construct(Security $security, ParameterBagInterface $params, TranslatorInterface $trans)
66
    {
67
        $this->security = $security;
68
        $this->params = $params;
69
        $this->trans = $trans;
70
    }
71
72
    public function configureOptions(OptionsResolver $resolver)
73
    {
74
        parent::configureOptions($resolver); // TODO: Change the autogenerated stub
75
        $resolver->setRequired('attachment_class');
76
    }
77
78
    public function buildForm(FormBuilderInterface $builder, array $options)
79
    {
80
        /** @var StructuralDBElement $entity */
81
        $entity = $options['data'];
82
        $is_new = $entity->getID() === null;
83
84
        $builder
85
            ->add('name', TextType::class, ['empty_data' => '', 'label' => $this->trans->trans('name.label'),
86
                'attr' => ['placeholder' => $this->trans->trans('part.name.placeholder')],
87
                'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ])
0 ignored issues
show
introduced by
The condition $is_new is always false.
Loading history...
88
89
            ->add('parent', StructuralEntityType::class, ['class' => get_class($entity),
90
                 'required' => false, 'label' =>  $this->trans->trans('parent.label'),
91
                'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity), ])
0 ignored issues
show
introduced by
The condition $is_new is always false.
Loading history...
92
93
            ->add('not_selectable', CheckboxType::class, ['required' => false,
94
                'label' =>  $this->trans->trans('entity.edit.not_selectable'),
95
                'help' =>  $this->trans->trans('entity.edit.not_selectable.help'),
96
                'label_attr' => ['class' => 'checkbox-custom'],
97
                'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity) ])
0 ignored issues
show
introduced by
The condition $is_new is always false.
Loading history...
98
99
            ->add('comment', CKEditorType::class, ['required' => false, 'empty_data' => '',
100
                'label' =>  $this->trans->trans('comment.label'),
101
                'attr' => ['rows' => 4], 'help' =>  $this->trans->trans('bbcode.hint'),
102
                'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity)]);
0 ignored issues
show
introduced by
The condition $is_new is always false.
Loading history...
103
104
            $this->additionalFormElements($builder, $options, $entity);
105
106
        //Attachment section
107
        $builder->add('attachments', CollectionType::class, [
108
            'entry_type' => AttachmentFormType::class,
109
            'allow_add' => true,
110
            'allow_delete' => true,
111
            'label' => false,
112
            'entry_options' => [
113
                'data_class' => $options['attachment_class'],
114
            ],
115
            'by_reference' => false
116
        ]);
117
118
            //Buttons
119
            $builder->add('save', SubmitType::class, [
120
                'label' =>  $is_new ?  $this->trans->trans('entity.create') :  $this->trans->trans('entity.edit.save'),
0 ignored issues
show
introduced by
The condition $is_new is always false.
Loading history...
121
                'attr' => ['class' => $is_new ? 'btn-success' : ''],
0 ignored issues
show
introduced by
The condition $is_new is always false.
Loading history...
122
                'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity)])
0 ignored issues
show
introduced by
The condition $is_new is always false.
Loading history...
123
            ->add('reset', ResetType::class, ['label' => 'entity.edit.reset',
124
                'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity)]);
0 ignored issues
show
introduced by
The condition $is_new is always false.
Loading history...
125
    }
126
127
    protected function additionalFormElements(FormBuilderInterface $builder, array $options, NamedDBElement $entity)
0 ignored issues
show
Unused Code introduced by
The parameter $entity is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

127
    protected function additionalFormElements(FormBuilderInterface $builder, array $options, /** @scrutinizer ignore-unused */ NamedDBElement $entity)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
128
    {
129
        //Empty for Base
130
    }
131
}