Dont call translator inside the form classes.

Translation is already done in the templates, so translator calls in form classes, are bad for performance and readability.
This commit is contained in:
Jan Böhmer 2019-12-26 14:53:13 +01:00
parent e7b920c4fe
commit 89acfff857
28 changed files with 1875 additions and 2259 deletions

View file

@ -34,10 +34,10 @@ class AttachmentTypeAdminForm extends BaseEntityAdminForm
{
protected $filterTools;
public function __construct(Security $security, ParameterBagInterface $params, TranslatorInterface $trans, FileTypeFilterTools $filterTools)
public function __construct(Security $security, ParameterBagInterface $params, FileTypeFilterTools $filterTools)
{
$this->filterTools = $filterTools;
parent::__construct($security, $params, $trans);
parent::__construct($security, $params);
}
protected function additionalFormElements(FormBuilderInterface $builder, array $options, NamedDBElement $entity)
@ -45,9 +45,9 @@ class AttachmentTypeAdminForm extends BaseEntityAdminForm
$is_new = null === $entity->getID();
$builder->add('filetype_filter', TextType::class, ['required' => false,
'label' => $this->trans->trans('attachment_type.edit.filetype_filter'),
'help' => $this->trans->trans('attachment_type.edit.filetype_filter.help'),
'attr' => ['placeholder' => $this->trans->trans('attachment_type.edit.filetype_filter.placeholder')],
'label' => 'attachment_type.edit.filetype_filter',
'help' => 'attachment_type.edit.filetype_filter.help',
'attr' => ['placeholder' => 'attachment_type.edit.filetype_filter.placeholder'],
'empty_data' => '',
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]);

View file

@ -44,13 +44,11 @@ class BaseEntityAdminForm extends AbstractType
{
protected $security;
protected $params;
protected $trans;
public function __construct(Security $security, ParameterBagInterface $params, TranslatorInterface $trans)
public function __construct(Security $security, ParameterBagInterface $params)
{
$this->security = $security;
$this->params = $params;
$this->trans = $trans;
}
public function configureOptions(OptionsResolver $resolver)
@ -66,23 +64,23 @@ class BaseEntityAdminForm extends AbstractType
$is_new = null === $entity->getID();
$builder
->add('name', TextType::class, ['empty_data' => '', 'label' => $this->trans->trans('name.label'),
'attr' => ['placeholder' => $this->trans->trans('part.name.placeholder')],
->add('name', TextType::class, ['empty_data' => '', 'label' => 'name.label',
'attr' => ['placeholder' =>'part.name.placeholder'],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ])
->add('parent', StructuralEntityType::class, ['class' => \get_class($entity),
'required' => false, 'label' => $this->trans->trans('parent.label'),
'required' => false, 'label' => 'parent.label',
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity), ])
->add('not_selectable', CheckboxType::class, ['required' => false,
'label' => $this->trans->trans('entity.edit.not_selectable'),
'help' => $this->trans->trans('entity.edit.not_selectable.help'),
'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' => $this->trans->trans('comment.label'),
'attr' => ['rows' => 4], 'help' => $this->trans->trans('bbcode.hint'),
'label' => 'comment.label',
'attr' => ['rows' => 4], 'help' => 'bbcode.hint',
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]);
$this->additionalFormElements($builder, $options, $entity);
@ -103,13 +101,13 @@ class BaseEntityAdminForm extends AbstractType
$builder->add('master_picture_attachment', MasterPictureAttachmentType::class, [
'required' => false,
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity),
'label' => $this->trans->trans('part.edit.master_attachment'),
'label' => 'part.edit.master_attachment',
'entity' => $entity,
]);
//Buttons
$builder->add('save', SubmitType::class, [
'label' => $is_new ? $this->trans->trans('entity.create') : $this->trans->trans('entity.edit.save'),
'label' => $is_new ? 'entity.create' : 'entity.edit.save',
'attr' => ['class' => $is_new ? 'btn-success' : ''],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ])
->add('reset', ResetType::class, ['label' => 'entity.edit.reset',

View file

@ -33,46 +33,46 @@ class CategoryAdminForm extends BaseEntityAdminForm
$is_new = null === $entity->getID();
$builder->add('disable_footprints', CheckboxType::class, ['required' => false,
'label' => $this->trans->trans('category.edit.disable_footprints'),
'help' => $this->trans->trans('category.edit.disable_footprints.help'),
'label' => 'category.edit.disable_footprints',
'help' => 'category.edit.disable_footprints.help',
'label_attr' => ['class' => 'checkbox-custom'],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]);
$builder->add('disable_manufacturers', CheckboxType::class, ['required' => false,
'label' => $this->trans->trans('category.edit.disable_manufacturers'),
'help' => $this->trans->trans('category.edit.disable_manufacturers.help'),
'label' => 'category.edit.disable_manufacturers',
'help' => 'category.edit.disable_manufacturers.help',
'label_attr' => ['class' => 'checkbox-custom'],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]);
$builder->add('disable_autodatasheets', CheckboxType::class, ['required' => false,
'label' => $this->trans->trans('category.edit.disable_autodatasheets'),
'help' => $this->trans->trans('category.edit.disable_autodatasheets.help'),
'label' => 'category.edit.disable_autodatasheets',
'help' => 'category.edit.disable_autodatasheets.help',
'label_attr' => ['class' => 'checkbox-custom'],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]);
$builder->add('disable_properties', CheckboxType::class, ['required' => false,
'label' => $this->trans->trans('category.edit.disable_properties'),
'help' => $this->trans->trans('category.edit.disable_properties.help'),
'label' => 'category.edit.disable_properties',
'help' => 'category.edit.disable_properties.help',
'label_attr' => ['class' => 'checkbox-custom'],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]);
$builder->add('partname_hint', TextType::class, ['required' => false, 'empty_data' => '',
'label' => $this->trans->trans('category.edit.partname_hint'),
'attr' => ['placeholder' => $this->trans->trans('category.edit.partname_hint.placeholder')],
'label' => 'category.edit.partname_hint',
'attr' => ['placeholder' => 'category.edit.partname_hint.placeholder'],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]);
$builder->add('partname_regex', TextType::class, ['required' => false, 'empty_data' => '',
'label' => $this->trans->trans('category.edit.partname_regex'),
'label' => 'category.edit.partname_regex',
'attr' => ['placeholder' => 'category.edit.partname_regex.placeholder'],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]);
$builder->add('default_description', TextType::class, ['required' => false, 'empty_data' => '',
'label' => $this->trans->trans('category.edit.default_description'),
'attr' => ['placeholder' => $this->trans->trans('category.edit.default_description.placeholder')],
'label' => 'category.edit.default_description',
'attr' => ['placeholder' => 'category.edit.default_description.placeholder'],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]);
$builder->add('default_comment', TextType::class, ['required' => false, 'empty_data' => '',
'label' => $this->trans->trans('category.edit.default_comment'),
'label' => 'category.edit.default_comment',
'attr' => ['placeholder' => $this->trans->trans('category.edit.default_comment.placeholder')],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]);
}

View file

@ -35,46 +35,46 @@ class CompanyForm extends BaseEntityAdminForm
$is_new = null === $entity->getID();
$builder->add('address', TextareaType::class, [
'label' => $this->trans->trans('company.edit.address'),
'label' => 'company.edit.address',
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity),
'attr' => ['placeholder' => $this->trans->trans('company.edit.address.placeholder')], 'required' => false,
'attr' => ['placeholder' => 'company.edit.address.placeholder'], 'required' => false,
'empty_data' => '',
]);
$builder->add('phone_number', TelType::class, [
'label' => $this->trans->trans('company.edit.phone_number'),
'label' => 'company.edit.phone_number',
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity),
'attr' => ['placeholder' => $this->trans->trans('company.edit.phone_number.placeholder')],
'attr' => ['placeholder' => 'company.edit.phone_number.placeholder'],
'required' => false,
'empty_data' => '',
]);
$builder->add('fax_number', TelType::class, [
'label' => $this->trans->trans('company.edit.fax_number'),
'label' => 'company.edit.fax_number',
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity),
'attr' => ['placeholder' => 'company.fax_number.placeholder'], 'required' => false,
'empty_data' => '',
]);
$builder->add('email_address', EmailType::class, [
'label' => $this->trans->trans('company.edit.email'),
'label' => 'company.edit.email',
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity),
'attr' => ['placeholder' => $this->trans->trans('company.edit.email.placeholder')], 'required' => false,
'attr' => ['placeholder' => 'company.edit.email.placeholder'], 'required' => false,
'empty_data' => '',
]);
$builder->add('website', UrlType::class, [
'label' => $this->trans->trans('company.edit.website'),
'label' => 'company.edit.website',
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity),
'attr' => ['placeholder' => $this->trans->trans('company.edit.website.placeholder')], 'required' => false,
'attr' => ['placeholder' => 'company.edit.website.placeholder'], 'required' => false,
'empty_data' => '',
]);
$builder->add('auto_product_url', UrlType::class, [
'label' => $this->trans->trans('company.edit.auto_product_url'),
'help' => $this->trans->trans('company.edit.auto_product_url.help'),
'label' => 'company.edit.auto_product_url',
'help' => 'company.edit.auto_product_url.help',
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity),
'attr' => ['placeholder' => $this->trans->trans('company.edit.auto_product_url.placeholder')],
'attr' => ['placeholder' => 'company.edit.auto_product_url.placeholder'],
'required' => false,
'empty_data' => '',
]);

View file

@ -34,14 +34,14 @@ class CurrencyAdminForm extends BaseEntityAdminForm
$builder->add('iso_code', CurrencyType::class, [
'required' => false,
'label' => $this->trans->trans('currency.edit.iso_code'),
'label' => 'currency.edit.iso_code',
'preferred_choices' => ['EUR', 'USD', 'GBP', 'JPY', 'CNY'],
'attr' => ['class' => 'selectpicker', 'data-live-search' => true],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]);
$builder->add('exchange_rate', MoneyType::class, [
'required' => false,
'label' => $this->trans->trans('currency.edit.exchange_rate'),
'label' => 'currency.edit.exchange_rate',
'currency' => $this->params->get('default_currency'),
'scale' => 6,
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]);

View file

@ -32,7 +32,7 @@ class FootprintAdminForm extends BaseEntityAdminForm
$builder->add('footprint_3d', MasterPictureAttachmentType::class, [
'required' => false,
'disabled' => !$this->security->isGranted(null === $entity->getID() ? 'create' : 'edit', $entity),
'label' => $this->trans->trans('footprint.edit.3d_model'),
'label' => 'footprint.edit.3d_model',
'filter' => '3d_model',
'entity' => $entity,
]);

View file

@ -36,12 +36,10 @@ use Symfony\Contracts\Translation\TranslatorInterface;
class ImportType extends AbstractType
{
protected $security;
protected $trans;
public function __construct(Security $security, TranslatorInterface $trans)
public function __construct(Security $security)
{
$this->security = $security;
$this->trans = $trans;
}
public function buildForm(FormBuilderInterface $builder, array $options)
@ -57,33 +55,33 @@ class ImportType extends AbstractType
->add('format', ChoiceType::class, [
'choices' => ['JSON' => 'json', 'XML' => 'xml', 'CSV' => 'csv', 'YAML' => 'yaml'],
'label' => $this->trans->trans('export.format'),
'label' => 'export.format',
'disabled' => $disabled, ])
->add('csv_separator', TextType::class, ['data' => ';',
'label' => $this->trans->trans('import.csv_separator'),
'label' => 'import.csv_separator',
'disabled' => $disabled, ]);
if ($entity instanceof StructuralDBElement) {
$builder->add('parent', StructuralEntityType::class, [
'class' => $data['entity_class'],
'required' => false,
'label' => $this->trans->trans('parent.label'),
'label' => 'parent.label',
'disabled' => $disabled,
]);
}
$builder->add('file', FileType::class, [
'label' => $this->trans->trans('import.file'),
'label' => 'import.file',
'attr' => ['class' => 'file', 'data-show-preview' => 'false', 'data-show-upload' => 'false'],
'disabled' => $disabled,
])
->add('preserve_children', CheckboxType::class, ['data' => true, 'required' => false,
'label' => $this->trans->trans('import.preserve_children'),
'label' => 'import.preserve_children',
'label_attr' => ['class' => 'checkbox-custom'], 'disabled' => $disabled, ])
->add('abort_on_validation_error', CheckboxType::class, ['data' => true, 'required' => false,
'label' => $this->trans->trans('import.abort_on_validation'),
'help' => $this->trans->trans('import.abort_on_validation.help'),
'label' => 'import.abort_on_validation',
'help' => 'import.abort_on_validation.help',
'label_attr' => ['class' => 'checkbox-custom'], 'disabled' => $disabled, ])
//Buttons

View file

@ -33,12 +33,10 @@ use Symfony\Contracts\Translation\TranslatorInterface;
class MassCreationForm extends AbstractType
{
protected $security;
protected $translator;
public function __construct(Security $security, TranslatorInterface $translator)
public function __construct(Security $security)
{
$this->security = $security;
$this->translator = $translator;
}
public function buildForm(FormBuilderInterface $builder, array $options)
@ -52,10 +50,10 @@ class MassCreationForm extends AbstractType
$builder
->add('lines', TextareaType::class, ['data' => '',
'label' => $this->translator->trans('mass_creation.lines'),
'label' => 'mass_creation.lines',
'disabled' => $disabled, 'required' => true,
'attr' => [
'placeholder' => $this->translator->trans('mass_creation.lines.placeholder'),
'placeholder' => 'mass_creation.lines.placeholder',
'rows' => 10,
],
]);
@ -63,13 +61,13 @@ class MassCreationForm extends AbstractType
$builder->add('parent', StructuralEntityType::class, [
'class' => $data['entity_class'],
'required' => false,
'label' => $this->translator->trans('parent.label'),
'label' => 'parent.label',
'disabled' => $disabled, ]);
}
//Buttons
$builder->add('create', SubmitType::class, [
'label' => $this->translator->trans('entity.mass_creation.btn'),
'label' => 'entity.mass_creation.btn',
'disabled' => $disabled,
]);
}

View file

@ -33,20 +33,20 @@ class MeasurementUnitAdminForm extends BaseEntityAdminForm
$is_new = null === $entity->getID();
$builder->add('is_integer', CheckboxType::class, ['required' => false,
'label' => $this->trans->trans('measurement_unit.edit.is_integer'),
'help' => $this->trans->trans('measurement_unit.edit.is_integer.help'),
'label' => 'measurement_unit.edit.is_integer',
'help' => 'measurement_unit.edit.is_integer.help',
'label_attr' => ['class' => 'checkbox-custom'],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]);
$builder->add('use_si_prefix', CheckboxType::class, ['required' => false,
'label' => $this->trans->trans('measurement_unit.edit.use_si_prefix'),
'help' => $this->trans->trans('measurement_unit.edit.use_si_prefix.help'),
'label' => 'measurement_unit.edit.use_si_prefix',
'help' => 'measurement_unit.edit.use_si_prefix.help',
'label_attr' => ['class' => 'checkbox-custom'],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]);
$builder->add('unit', TextType::class, ['required' => false,
'label' => $this->trans->trans('measurement_unit.edit.unit_symbol'),
'attr' => ['placeholder' => $this->trans->trans('measurement_unit.edit.unit_symbol.placeholder')],
'label' => 'measurement_unit.edit.unit_symbol',
'attr' => ['placeholder' => 'measurement_unit.edit.unit_symbol.placeholder'],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]);
}
}

View file

@ -35,29 +35,29 @@ class StorelocationAdminForm extends BaseEntityAdminForm
$builder->add('is_full', CheckboxType::class, [
'required' => false,
'label' => $this->trans->trans('storelocation.edit.is_full.label'),
'help' => $this->trans->trans('storelocation.edit.is_full.help'),
'label' => 'storelocation.edit.is_full.label',
'help' => 'storelocation.edit.is_full.help',
'label_attr' => ['class' => 'checkbox-custom'],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity), ]);
$builder->add('limit_to_existing_parts', CheckboxType::class, [
'required' => false,
'label' => $this->trans->trans('storelocation.limit_to_existing.label'),
'help' => $this->trans->trans('storelocation.limit_to_existing.help'),
'label' => 'storelocation.limit_to_existing.label',
'help' => 'storelocation.limit_to_existing.help',
'label_attr' => ['class' => 'checkbox-custom'],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity), ]);
$builder->add('only_single_part', CheckboxType::class, [
'required' => false,
'label' => $this->trans->trans('storelocation.only_single_part.label'),
'help' => $this->trans->trans('storelocation.only_single_part.help'),
'label' => 'storelocation.only_single_part.label',
'help' => 'storelocation.only_single_part.help',
'label_attr' => ['class' => 'checkbox-custom'],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity), ]);
$builder->add('storage_type', StructuralEntityType::class, [
'required' => false,
'label' => $this->trans->trans('storelocation.storage_type.label'),
'help' => $this->trans->trans('storelocation.storage_type.help'),
'label' => 'storelocation.storage_type.label',
'help' => 'storelocation.storage_type.help',
'class' => MeasurementUnit::class, 'disable_not_selectable' => true,
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity), ]);
}

View file

@ -38,7 +38,7 @@ class SupplierForm extends CompanyForm
$builder->add('default_currency', StructuralEntityType::class, [
'class' => Currency::class,
'required' => false,
'label' => $this->trans->trans('supplier.edit.default_currency'),
'label' => 'supplier.edit.default_currency',
'disable_not_selectable' => true,
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity), ]);
@ -46,7 +46,7 @@ class SupplierForm extends CompanyForm
'required' => false,
'currency' => $this->params->get('default_currency'),
'scale' => 3,
'label' => $this->trans->trans('supplier.shipping_costs.label'),
'label' => 'supplier.shipping_costs.label',
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity),
]);
}