Explicitly call translator interface for form labels.

This helps us to extract the translation keys.
This commit is contained in:
Jan Böhmer 2019-09-04 15:53:18 +02:00
parent f132c65964
commit 758a2ba25d
16 changed files with 391 additions and 226 deletions

View file

@ -46,17 +46,21 @@ use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Security\Core\Security; use Symfony\Component\Security\Core\Security;
use Symfony\Component\Translation\Reader\TranslationReader;
use Symfony\Contracts\Translation\TranslatorInterface;
class BaseEntityAdminForm extends AbstractType class BaseEntityAdminForm extends AbstractType
{ {
protected $security; protected $security;
protected $params; protected $params;
protected $trans;
public function __construct(Security $security, ParameterBagInterface $params) public function __construct(Security $security, ParameterBagInterface $params, TranslatorInterface $trans)
{ {
$this->security = $security; $this->security = $security;
$this->params = $params; $this->params = $params;
$this->trans = $trans;
} }
@ -67,26 +71,30 @@ class BaseEntityAdminForm extends AbstractType
$is_new = $entity->getID() === null; $is_new = $entity->getID() === null;
$builder $builder
->add('name', TextType::class, ['empty_data' => '', 'label' => 'name.label', ->add('name', TextType::class, ['empty_data' => '', 'label' => $this->trans->trans('name.label'),
'attr' => ['placeholder' => 'part.name.placeholder'], 'attr' => ['placeholder' => $this->trans->trans('part.name.placeholder')],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]) 'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ])
->add('parent', StructuralEntityType::class, ['class' => get_class($entity), ->add('parent', StructuralEntityType::class, ['class' => get_class($entity),
'required' => false, 'label' => 'parent.label', 'required' => false, 'label' => $this->trans->trans('parent.label'),
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity), ]) 'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity), ])
->add('not_selectable', CheckboxType::class, ['required' => false, ->add('not_selectable', CheckboxType::class, ['required' => false,
'label' => 'not_selectable.label', 'help' => 'not_selectable.help', 'label_attr'=> ['class' => 'checkbox-custom'], 'label' => $this->trans->trans('entity.edit.not_selectable'),
'help' => $this->trans->trans('entity.edit.not_selectable.help'),
'label_attr' => ['class' => 'checkbox-custom'],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity) ]) 'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity) ])
->add('comment', CKEditorType::class, ['required' => false, 'empty_data' => '', ->add('comment', CKEditorType::class, ['required' => false, 'empty_data' => '',
'label' => 'comment.label', 'attr' => ['rows' => 4], 'help' => 'bbcode.hint', 'label' => $this->trans->trans('comment.label'),
'attr' => ['rows' => 4], 'help' => $this->trans->trans('bbcode.hint'),
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity)]); 'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity)]);
$this->additionalFormElements($builder, $options, $entity); $this->additionalFormElements($builder, $options, $entity);
//Buttons //Buttons
$builder->add('save', SubmitType::class, ['label' => $is_new ? 'entity.create' : 'entity.edit.save', $builder->add('save', SubmitType::class, [
'label' => $is_new ? $this->trans->trans('entity.create') : $this->trans->trans('entity.edit.save'),
'attr' => ['class' => $is_new ? 'btn-success' : ''], 'attr' => ['class' => $is_new ? 'btn-success' : ''],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity)]) 'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity)])
->add('reset', ResetType::class, ['label' => 'entity.edit.reset', ->add('reset', ResetType::class, ['label' => 'entity.edit.reset',

View file

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

View file

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

View file

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

View file

@ -33,6 +33,7 @@ namespace App\Form\AdminPages;
use App\Entity\Base\StructuralDBElement; use App\Entity\Base\StructuralDBElement;
use App\Form\Type\StructuralEntityType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Bundle\MakerBundle\Str; use Symfony\Bundle\MakerBundle\Str;
use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\AbstractType;
@ -43,15 +44,18 @@ use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Security\Core\Security; use Symfony\Component\Security\Core\Security;
use Symfony\Contracts\Translation\TranslatorInterface;
class ImportType extends AbstractType class ImportType extends AbstractType
{ {
protected $security; protected $security;
protected $trans;
public function __construct(Security $security) public function __construct(Security $security, TranslatorInterface $trans)
{ {
$this->security = $security; $this->security = $security;
$this->trans = $trans;
} }
public function buildForm(FormBuilderInterface $builder, array $options) public function buildForm(FormBuilderInterface $builder, array $options)
@ -60,31 +64,42 @@ class ImportType extends AbstractType
$data = $options['data']; $data = $options['data'];
//Disable import if user is not allowed to create elements. //Disable import if user is not allowed to create elements.
$entity = new $data['entity_class']; $entity = new $data['entity_class']();
$perm_name = "create"; $perm_name = "create";
$disabled = ! $this->security->isGranted($perm_name, $entity); $disabled = ! $this->security->isGranted($perm_name, $entity);
$builder $builder
->add('format', ChoiceType::class, ['choices' => ->add('format', ChoiceType::class, [
['JSON' => 'json', 'XML' => 'xml','CSV'=>'csv' ,'YAML' => 'yaml'], 'label' => 'export.format', 'choices' => ['JSON' => 'json', 'XML' => 'xml','CSV' => 'csv' ,'YAML' => 'yaml'],
'label' => $this->trans->trans('export.format'),
'disabled' => $disabled]) 'disabled' => $disabled])
->add('csv_separator', TextType::class, ['data' => ';', 'label' => 'import.csv_separator', ->add('csv_separator', TextType::class, ['data' => ';',
'label' => $this->trans->trans('import.csv_separator'),
'disabled' => $disabled]); 'disabled' => $disabled]);
if($entity instanceof StructuralDBElement) {
$builder-> if ($entity instanceof StructuralDBElement) {
add('parent', EntityType::class, ['class' => $data['entity_class'], 'choice_label' => 'full_path', $builder->add('parent', StructuralEntityType::class, [
'attr' => ['class' => 'selectpicker', 'data-live-search' => true], 'required' => false, 'class' => $data['entity_class'],
'label' => 'parent.label', 'disabled' => $disabled]); 'required' => false,
} 'label' => $this->trans->trans('parent.label'),
$builder->add('file', FileType::class, ['label' => 'import.file', 'disabled' => $disabled
'attr' => ['class' => 'file', 'data-show-preview' => 'false', 'data-show-upload' => 'false'], 'disabled' => $disabled]) ]);
}
$builder->add('file', FileType::class, [
'label' => $this->trans->trans('import.file'),
'attr' => ['class' => 'file', 'data-show-preview' => 'false', 'data-show-upload' => 'false'],
'disabled' => $disabled
])
->add('preserve_children', CheckboxType::class, ['data' => true, 'required' => false, ->add('preserve_children', CheckboxType::class, ['data' => true, 'required' => false,
'label' => 'import.preserve_children', 'label_attr'=> ['class' => 'checkbox-custom'], 'disabled' => $disabled]) 'label' => $this->trans->trans('import.preserve_children'),
'label_attr' => ['class' => 'checkbox-custom'], 'disabled' => $disabled])
->add('abort_on_validation_error', CheckboxType::class, ['data' => true, 'required' => false, ->add('abort_on_validation_error', CheckboxType::class, ['data' => true, 'required' => false,
'label' => 'import.abort_on_validation', 'help'=> 'import.abort_on_validation.help', 'label' => $this->trans->trans('import.abort_on_validation'),
'label_attr'=> ['class' => 'checkbox-custom'], 'disabled' => $disabled]) 'help' => $this->trans->trans('import.abort_on_validation.help'),
'label_attr' => ['class' => 'checkbox-custom'], 'disabled' => $disabled])
//Buttons //Buttons
->add('import', SubmitType::class, ['label' => 'import.btn', 'disabled' => $disabled]); ->add('import', SubmitType::class, ['label' => 'import.btn', 'disabled' => $disabled]);

View file

@ -33,6 +33,7 @@ namespace App\Form\AdminPages;
use App\Entity\Base\StructuralDBElement; use App\Entity\Base\StructuralDBElement;
use App\Form\Type\StructuralEntityType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType; use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
@ -43,14 +44,17 @@ use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Security\Core\Security; use Symfony\Component\Security\Core\Security;
use Symfony\Contracts\Translation\TranslatorInterface;
class MassCreationForm extends AbstractType class MassCreationForm extends AbstractType
{ {
protected $security; protected $security;
protected $translator;
public function __construct(Security $security) public function __construct(Security $security, TranslatorInterface $translator)
{ {
$this->security = $security; $this->security = $security;
$this->translator = $translator;
} }
public function buildForm(FormBuilderInterface $builder, array $options) public function buildForm(FormBuilderInterface $builder, array $options)
@ -64,18 +68,26 @@ class MassCreationForm extends AbstractType
$disabled = ! $this->security->isGranted($perm_name, $entity); $disabled = ! $this->security->isGranted($perm_name, $entity);
$builder $builder
->add('lines', TextareaType::class, ['data' => '', 'label' => 'mass_creation.lines', ->add('lines', TextareaType::class, ['data' => '',
'label' => $this->translator->trans('mass_creation.lines'),
'disabled' => $disabled, 'required' => true, 'disabled' => $disabled, 'required' => true,
'attr' => ['placeholder' => 'mass_creation.lines.placeholder', 'rows' => 10]]); 'attr' => [
'placeholder' => $this->translator->trans('mass_creation.lines.placeholder'),
'rows' => 10
]
]);
if ($entity instanceof StructuralDBElement) { if ($entity instanceof StructuralDBElement) {
$builder-> $builder->add('parent', StructuralEntityType::class, [
add('parent', EntityType::class, ['class' => $data['entity_class'], 'choice_label' => 'full_path', 'class' => $data['entity_class'],
'attr' => ['class' => 'selectpicker', 'data-live-search' => true], 'required' => false, 'required' => false,
'label' => 'parent.label', 'disabled' => $disabled]); 'label' => $this->translator->trans('parent.label'),
'disabled' => $disabled]);
} }
$builder //Buttons
//Buttons $builder->add('create', SubmitType::class, [
->add('create', SubmitType::class, ['label' => 'mass_creation.btn', 'disabled' => $disabled]); 'label' => $this->translator->trans('entity.mass_creation.btn'),
'disabled' => $disabled
]);
} }
} }

View file

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

View file

@ -46,23 +46,31 @@ class StorelocationAdminForm extends BaseEntityAdminForm
{ {
$is_new = $entity->getID() === null; $is_new = $entity->getID() === null;
$builder->add('is_full', CheckboxType::class, ['required' => false, $builder->add('is_full', CheckboxType::class, [
'label' => 'storelocation.is_full.label', 'help' => 'storelocation.is_full.help', 'required' => false,
'label_attr'=> ['class' => 'checkbox-custom'], 'label' => $this->trans->trans('storelocation.edit.is_full.label'),
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity)]); 'help' => $this->trans->trans('storelocation.edit.is_full.help'),
'label_attr' => ['class' => 'checkbox-custom'],
$builder->add('limit_to_existing_parts', CheckboxType::class, ['required' => false,
'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)]); 'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity)]);
$builder->add('only_single_part', CheckboxType::class, ['required' => false, $builder->add('limit_to_existing_parts', CheckboxType::class, [
'label' => 'storelocation.only_single_part.label', 'help' => 'storelocation.only_single_part.help', 'required' => false,
'label_attr'=> ['class' => 'checkbox-custom'], 'label' => $this->trans->trans('storelocation.limit_to_existing.label'),
'help' => $this->trans->trans('storelocation.limit_to_existing.help'),
'label_attr' => ['class' => 'checkbox-custom'],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity)]); 'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity)]);
$builder->add('storage_type', StructuralEntityType::class, ['required' => false, $builder->add('only_single_part', CheckboxType::class, [
'label' => 'storelocation.storage_type.label', 'help' => 'storelocation.storage_type.help', 'required' => false,
'label' => $this->trans->trans('storelocation.only_single_part.label'),
'help' => $this->trans->trans('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'),
'class' => MeasurementUnit::class, 'disable_not_selectable' => true, 'class' => MeasurementUnit::class, 'disable_not_selectable' => true,
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity)]); 'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity)]);

View file

@ -47,55 +47,26 @@ use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\UrlType; use Symfony\Component\Form\Extension\Core\Type\UrlType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
class SupplierForm extends BaseEntityAdminForm class SupplierForm extends CompanyForm
{ {
protected function additionalFormElements(FormBuilderInterface $builder, array $options, NamedDBElement $entity) protected function additionalFormElements(FormBuilderInterface $builder, array $options, NamedDBElement $entity)
{ {
$is_new = $entity->getID() === null; $is_new = $entity->getID() === null;
$builder->add('address', TextareaType::class, ['label' => 'company.address.label', parent::additionalFormElements($builder, $options, $entity);
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity),
'attr' => ['placeholder' => 'company.address.placeholder'], 'required' => false,
'empty_data' => ''
]);
$builder->add('phone_number', TelType::class, ['label' => 'company.phone_number.label', $builder->add('default_currency', StructuralEntityType::class, [
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), 'class' => Currency::class,
'attr' => ['placeholder' => 'company.phone_number.placeholder'], 'required' => false, 'required' => false,
'empty_data' => '' 'label' => $this->trans->trans('supplier.edit.default_currency'),
]); 'disable_not_selectable' => true,
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity), ]);
$builder->add('fax_number', TelType::class, ['label' => 'company.fax_number.label', $builder->add('shipping_costs', MoneyType::class, [
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), 'required' => false,
'attr' => ['placeholder' => 'company.fax_number.placeholder'], 'required' => false, 'currency' => $this->params->get('default_currency'),
'empty_data' => '' 'scale' => 3,
]); 'label' => $this->trans->trans('supplier.shipping_costs.label'),
$builder->add('email_address', EmailType::class, ['label' => 'company.email.label',
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity),
'attr' => ['placeholder' => 'company.email.placeholder'], 'required' => false,
'empty_data' => ''
]);
$builder->add('website', UrlType::class, ['label' => 'company.website.label',
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity),
'attr' => ['placeholder' => 'company.website.placeholder'], 'required' => false,
'empty_data' => ''
]);
$builder->add('auto_product_url', UrlType::class, ['label' => 'company.auto_product_url.label',
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity),
'attr' => ['placeholder' => 'company.auto_product_url.placeholder'], 'required' => false,
'empty_data' => ''
]);
$builder->add('default_currency', StructuralEntityType::class, ['class' => Currency::class,
'required' => false, 'label' => 'supplier.default_currency.label', 'disable_not_selectable' => true,
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity), ]);
$builder->add('shipping_costs', MoneyType::class, [ 'required' => false,
'currency' => $this->params->get('default_currency'), 'scale' => 3,
'label' => 'supplier.shipping_costs.label',
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity) 'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity)
]); ]);
} }

View file

@ -46,35 +46,37 @@ use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\File; use Symfony\Component\Validator\Constraints\File;
use Symfony\Component\Validator\Constraints\Url; use Symfony\Component\Validator\Constraints\Url;
use Symfony\Contracts\Translation\TranslatorInterface;
class AttachmentFormType extends AbstractType class AttachmentFormType extends AbstractType
{ {
protected $attachment_helper; protected $attachment_helper;
protected $trans;
public function __construct(AttachmentHelper $attachmentHelper) public function __construct(AttachmentHelper $attachmentHelper, TranslatorInterface $trans)
{ {
$this->attachment_helper = $attachmentHelper; $this->attachment_helper = $attachmentHelper;
$this->trans = $trans;
} }
public function buildForm(FormBuilderInterface $builder, array $options) public function buildForm(FormBuilderInterface $builder, array $options)
{ {
$builder->add('name', TextType::class, $builder->add('name', TextType::class, [
[ 'label' => $this->trans->trans('attachment.edit.name')
'label' => 'attachment.edit.name' ])
])
->add('attachment_type', StructuralEntityType::class, [ ->add('attachment_type', StructuralEntityType::class, [
'label' => 'attachment.edit.attachment_type', 'label' => $this->trans->trans('attachment.edit.attachment_type'),
'class' => AttachmentType::class, 'class' => AttachmentType::class,
'disable_not_selectable' => true, 'disable_not_selectable' => true,
]); ]);
$builder->add('showInTable', CheckboxType::class, ['required' => false, $builder->add('showInTable', CheckboxType::class, ['required' => false,
'label' => 'attachment.edit.show_in_table', 'label' => $this->trans->trans('attachment.edit.show_in_table'),
'attr' => ['class' => 'form-control-sm'], 'attr' => ['class' => 'form-control-sm'],
'label_attr' => ['class' => 'checkbox-custom']]); 'label_attr' => ['class' => 'checkbox-custom']]);
$builder->add('url', UrlType::class, [ $builder->add('url', UrlType::class, [
'label' => 'attachment.edit.url', 'label' => $this->trans->trans('attachment.edit.url'),
'required' => false, 'required' => false,
'constraints' => [ 'constraints' => [
new Url() new Url()
@ -82,7 +84,7 @@ class AttachmentFormType extends AbstractType
]); ]);
$builder->add('file', FileType::class, [ $builder->add('file', FileType::class, [
'label' => 'attachment.edit.file', 'label' => $this->trans->trans('attachment.edit.file'),
'mapped' => false, 'mapped' => false,
'required' => false, 'required' => false,
'attr' => ['class' => 'file', 'data-show-preview' => 'false', 'data-show-upload' => 'false'], 'attr' => ['class' => 'file', 'data-show-preview' => 'false', 'data-show-upload' => 'false'],

View file

@ -45,36 +45,45 @@ use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent; use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents; use Symfony\Component\Form\FormEvents;
use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Contracts\Translation\TranslatorInterface;
use function foo\func; use function foo\func;
class OrderdetailType extends AbstractType class OrderdetailType extends AbstractType
{ {
protected $trans;
public function __construct(TranslatorInterface $trans)
{
$this->trans = $trans;
}
public function buildForm(FormBuilderInterface $builder, array $options) public function buildForm(FormBuilderInterface $builder, array $options)
{ {
/** @var Orderdetail $orderdetail */ /** @var Orderdetail $orderdetail */
$orderdetail = $builder->getData(); $orderdetail = $builder->getData();
$builder->add('supplierpartnr', TextType::class, [ $builder->add('supplierpartnr', TextType::class, [
'label' => 'orderdetails.edit.supplierpartnr', 'label' => $this->trans->trans('orderdetails.edit.supplierpartnr'),
'attr' => ['placeholder' => $this->trans->trans('orderdetails.edit.supplierpartnr.placeholder')],
'required' => false, 'required' => false,
'empty_data' => "" 'empty_data' => ""
]); ]);
$builder->add('supplier', StructuralEntityType::class, [ $builder->add('supplier', StructuralEntityType::class, [
'class' => Supplier::class, 'disable_not_selectable' => true, 'class' => Supplier::class, 'disable_not_selectable' => true,
'label' => 'orderdetails.edit.supplier' 'label' => $this->trans->trans('orderdetails.edit.supplier')
]); ]);
$builder->add('supplier_product_url', UrlType::class, [ $builder->add('supplier_product_url', UrlType::class, [
'required' => false, 'required' => false,
'empty_data' => "", 'empty_data' => "",
'label' => 'orderdetails.edit.url' 'label' => $this->trans->trans('orderdetails.edit.url')
]); ]);
$builder->add('obsolete', CheckboxType::class, [ $builder->add('obsolete', CheckboxType::class, [
'required' => false, 'required' => false,
'label_attr' => ['class' => 'checkbox-custom'], 'label_attr' => ['class' => 'checkbox-custom'],
'label' => 'orderdetails.edit.obsolete' 'label' => $this->trans->trans('orderdetails.edit.obsolete')
]); ]);

View file

@ -91,59 +91,104 @@ class PartBaseType extends AbstractType
//Common section //Common section
$builder $builder
->add('name', TextType::class, ['empty_data' => '', 'label' => 'name.label', ->add('name', TextType::class, [
'attr' => ['placeholder' => 'part.name.placeholder'], 'empty_data' => '',
'disabled' => !$this->security->isGranted('name.edit', $part), ]) 'label' => $this->trans->trans('part.edit.name'),
->add('description', CKEditorType::class, ['required' => false, 'empty_data' => '', 'attr' => ['placeholder' => $this->trans->trans('part.edit.name.placeholder')],
'label' => 'description.label', 'help' => 'bbcode.hint', 'config_name' => 'description_config', 'disabled' => !$this->security->isGranted('name.edit', $part),
'attr' => ['placeholder' => 'part.description.placeholder', 'rows' => 2], ])
'disabled' => !$this->security->isGranted('description.edit', $part) ]) ->add('description', CKEditorType::class, [
->add('minAmount', SIUnitType::class, 'required' => false,
['attr' => ['min' => 0, 'placeholder' => 'part.mininstock.placeholder'], 'label' => 'mininstock.label', 'empty_data' => '',
'measurement_unit' => $part->getPartUnit(), 'label' => $this->trans->trans('part.edit.description'),
'disabled' => !$this->security->isGranted('mininstock.edit', $part), ]) 'config_name' => 'description_config',
->add('category', StructuralEntityType::class, ['class' => Category::class, 'attr' => ['placeholder' => $this->trans->trans('part.edit.description.placeholder'), 'rows' => 2],
'label' => 'category.label', 'disable_not_selectable' => true, 'disabled' => !$this->security->isGranted('description.edit', $part)
'disabled' => !$this->security->isGranted('move', $part), ]) ])
->add('footprint', StructuralEntityType::class, ['class' => Footprint::class, 'required' => false, ->add('minAmount', SIUnitType::class, [
'label' => 'footprint.label', 'disable_not_selectable' => true, 'attr' => ['min' => 0, 'placeholder' => $this->trans->trans('part.editmininstock.placeholder')],
'disabled' => !$this->security->isGranted('move', $part), ]) 'label' => $this->trans->trans('part.edit.mininstock'),
->add('tags', TextType::class, ['required' => false, 'label' => 'part.tags', 'empty_data' => "", 'measurement_unit' => $part->getPartUnit(),
'disabled' => !$this->security->isGranted('mininstock.edit', $part),
])
->add('category', StructuralEntityType::class, [
'class' => Category::class,
'label' => $this->trans->trans('part.edit.category'),
'disable_not_selectable' => true,
'disabled' => !$this->security->isGranted('move', $part),
])
->add('footprint', StructuralEntityType::class, [
'class' => Footprint::class,
'required' => false,
'label' => $this->trans->trans('part.edit.footprint'),
'disable_not_selectable' => true,
'disabled' => !$this->security->isGranted('move', $part),
])
->add('tags', TextType::class, [
'required' => false,
'label' => $this->trans->trans('part.edit.tags'),
'empty_data' => "",
'attr' => ['data-role' => 'tagsinput'], 'attr' => ['data-role' => 'tagsinput'],
'disabled' => !$this->security->isGranted('edit', $part) ]); 'disabled' => !$this->security->isGranted('edit', $part)
]);
//Manufacturer section //Manufacturer section
$builder->add('manufacturer', StructuralEntityType::class, ['class' => Manufacturer::class, $builder->add('manufacturer', StructuralEntityType::class, [
'required' => false, 'label' => 'manufacturer.label', 'disable_not_selectable' => true, 'class' => Manufacturer::class,
'disabled' => !$this->security->isGranted('manufacturer.edit', $part), ]) 'required' => false,
->add('manufacturer_product_url', UrlType::class, ['required' => false, 'empty_data' => '', 'label' => $this->trans->trans('part.edit.manufacturer.label'),
'label' => 'manufacturer_url.label', 'disable_not_selectable' => true,
'disabled' => !$this->security->isGranted('manufacturer.edit', $part), ]) 'disabled' => !$this->security->isGranted('manufacturer.edit', $part)
->add('manufacturer_product_number', TextType::class, ['required' => false, ])
'empty_data' => '', 'label' => 'part.mpn', ->add('manufacturer_product_url', UrlType::class, [
'required' => false,
'empty_data' => '',
'label' => $this->trans->trans('part.edit.manufacturer_url.label'),
'disabled' => !$this->security->isGranted('manufacturer.edit', $part),
])
->add('manufacturer_product_number', TextType::class, [
'required' => false,
'empty_data' => '',
'label' => $this->trans->trans('part.edit.mpn'),
'disabled' => !$this->security->isGranted('manufacturer.edit', $part)]) 'disabled' => !$this->security->isGranted('manufacturer.edit', $part)])
->add('manufacturing_status', ChoiceType::class, [ ->add('manufacturing_status', ChoiceType::class, [
'label' => 'part.manufacturing_status', 'label' => $this->trans->trans('part.edit.manufacturing_status'),
'choices' => $status_choices, 'choices' => $status_choices,
'required' => false, 'required' => false,
'disabled' => !$this->security->isGranted('manufacturer.edit', $part) 'disabled' => !$this->security->isGranted('manufacturer.edit', $part)
]); ]);
//Advanced section //Advanced section
$builder->add('needsReview', CheckboxType::class, ['label_attr'=> ['class' => 'checkbox-custom'], $builder->add('needsReview', CheckboxType::class, [
'required' => false, 'label' => 'part.edit.needs_review']) 'label_attr' => ['class' => 'checkbox-custom'],
->add('favorite', CheckboxType::class, ['label_attr'=> ['class' => 'checkbox-custom'], 'required' => false,
'required' => false, 'label' => 'part.edit.is_favorite']) 'label' => $this->trans->trans('part.edit.needs_review')
->add('mass', SIUnitType::class, ['unit' => 'g', ])
'label' => 'part.mass', 'required' => false]) ->add('favorite', CheckboxType::class, [
->add('partUnit', StructuralEntityType::class, ['class'=> MeasurementUnit::class, 'label_attr' => ['class' => 'checkbox-custom'],
'required' => false, 'disable_not_selectable' => true, 'label' => 'part.partUnit']); 'required' => false,
'label' => $this->trans->trans('part.edit.is_favorite')
])
->add('mass', SIUnitType::class, [
'unit' => 'g',
'label' => $this->trans->trans('part.edit.mass'),
'required' => false
])
->add('partUnit', StructuralEntityType::class, [
'class' => MeasurementUnit::class,
'required' => false,
'disable_not_selectable' => true,
'label' => $this->trans->trans('part.edit.partUnit')
]);
//Comment section //Comment section
$builder->add('comment', CKEditorType::class, ['required' => false, $builder->add('comment', CKEditorType::class, [
'label' => 'comment.label', 'attr' => ['rows' => 4], 'help' => 'bbcode.hint', 'required' => false,
'disabled' => !$this->security->isGranted('comment.edit', $part), 'empty_data' => '']); 'label' => $this->trans->trans('part.edit.comment'),
'attr' => ['rows' => 4],
'disabled' => !$this->security->isGranted('comment.edit', $part), 'empty_data' => ''
]);
//Part Lots section //Part Lots section
$builder->add('partLots', CollectionType::class, [ $builder->add('partLots', CollectionType::class, [
@ -169,7 +214,7 @@ class PartBaseType extends AbstractType
$builder->add('master_picture_attachment', EntityType::class, [ $builder->add('master_picture_attachment', EntityType::class, [
'required' => false, 'required' => false,
'label' => 'part.edit.master_attachment', 'label' => $this->trans->trans('part.edit.master_attachment'),
'class' => PartAttachment::class, 'class' => PartAttachment::class,
'attr' => ['class' => 'selectpicker'], 'attr' => ['class' => 'selectpicker'],
'choice_attr' => function ($choice, $key, $value) { 'choice_attr' => function ($choice, $key, $value) {
@ -200,8 +245,8 @@ class PartBaseType extends AbstractType
$builder $builder
//Buttons //Buttons
->add('save', SubmitType::class, ['label' => 'part.edit.save']) ->add('save', SubmitType::class, ['label' => $this->trans->trans('part.edit.save')])
->add('reset', ResetType::class, ['label' => 'part.edit.reset']); ->add('reset', ResetType::class, ['label' => $this->trans->trans('part.edit.reset')]);
} }
public function configureOptions(OptionsResolver $resolver) public function configureOptions(OptionsResolver $resolver)

View file

@ -51,45 +51,63 @@ use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents; use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormInterface;
use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Contracts\Translation\TranslatorInterface;
use function GuzzleHttp\Promise\queue; use function GuzzleHttp\Promise\queue;
class PartLotType extends AbstractType class PartLotType extends AbstractType
{ {
protected $trans;
public function __construct(TranslatorInterface $trans)
{
$this->trans = $trans;
}
public function buildForm(FormBuilderInterface $builder, array $options) public function buildForm(FormBuilderInterface $builder, array $options)
{ {
$builder->add('description', TextType::class, ['label' => 'part_lot.edit.description', $builder->add('description', TextType::class, [
'required' => false, 'empty_data' => "", 'attr' => ['class' => 'form-control-sm']]); 'label' => $this->trans->trans('part_lot.edit.description'),
'required' => false,
'empty_data' => "",
'attr' => ['class' => 'form-control-sm']
]);
$builder->add('storage_location', StructuralEntityType::class, ['class' => Storelocation::class, $builder->add('storage_location', StructuralEntityType::class, ['class' => Storelocation::class,
'label' => 'part_lot.edit.location', 'label' => $this->trans->trans('part_lot.edit.location'),
'required' => false, 'required' => false,
'disable_not_selectable' => true, 'disable_not_selectable' => true,
'attr' => ['class' => 'selectpicker form-control-sm', 'data-live-search' => true]]); 'attr' => ['class' => 'selectpicker form-control-sm', 'data-live-search' => true]
]);
$builder->add('amount', SIUnitType::class, [ $builder->add('amount', SIUnitType::class, [
'measurement_unit' => $options['measurement_unit'], 'measurement_unit' => $options['measurement_unit'],
'label' => 'part_lot.edit.amount', 'label' => $this->trans->trans('part_lot.edit.amount'),
'attr' => ['class' => 'form-control-sm'] 'attr' => ['class' => 'form-control-sm']
]); ]);
$builder->add('instock_unknown', CheckboxType::class, ['required' => false, $builder->add('instock_unknown', CheckboxType::class, ['required' => false,
'label' => 'part_lot.edit.instock_unknown', 'label' => $this->trans->trans('part_lot.edit.instock_unknown'),
'attr' => ['class' => 'form-control-sm'], 'attr' => ['class' => 'form-control-sm'],
'label_attr' => ['class' => 'checkbox-custom']]); 'label_attr' => ['class' => 'checkbox-custom']
]);
$builder->add('needs_refill', CheckboxType::class, ['label_attr' => ['class' => 'checkbox-custom'], $builder->add('needs_refill', CheckboxType::class, ['label_attr' => ['class' => 'checkbox-custom'],
'label' => 'part_lot.edit.needs_refill', 'label' => $this->trans->trans('part_lot.edit.needs_refill'),
'attr' => ['class' => 'form-control-sm'], 'attr' => ['class' => 'form-control-sm'],
'required' => false]); 'required' => false
]);
$builder->add('expirationDate', DateTimeType::class, [ $builder->add('expirationDate', DateTimeType::class, [
'label' => 'part_lot.edit.expiration_date', 'label' => $this->trans->trans('part_lot.edit.expiration_date'),
'attr' => [], 'attr' => [],
'required' => false]); 'required' => false]);
$builder->add('comment', TextType::class, ['label' => 'part_lot.edit.comment', $builder->add('comment', TextType::class, [
'label' => $this->trans->trans('part_lot.edit.comment'),
'attr' => ['class' => 'form-control-sm'], 'attr' => ['class' => 'form-control-sm'],
'required' => false, 'empty_data' => ""]); 'required' => false, 'empty_data' => ""
]);
} }

View file

@ -44,6 +44,7 @@ use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\Extension\Core\Type\NumberType; use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Contracts\Translation\TranslatorInterface;
class PricedetailType extends AbstractType class PricedetailType extends AbstractType
{ {

View file

@ -44,15 +44,18 @@ use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Security\Core\Security; use Symfony\Component\Security\Core\Security;
use Symfony\Contracts\Translation\TranslatorInterface;
class UserAdminForm extends AbstractType class UserAdminForm extends AbstractType
{ {
protected $security; protected $security;
protected $trans;
public function __construct(Security $security) public function __construct(Security $security, TranslatorInterface $trans)
{ {
$this->security = $security; $this->security = $security;
$this->trans = $trans;
} }
@ -63,30 +66,50 @@ class UserAdminForm extends AbstractType
$is_new = $entity->getID() === null; $is_new = $entity->getID() === null;
$builder $builder
->add('name', TextType::class, ['empty_data' => '', 'label' => 'user.username.label', ->add('name', TextType::class, [
'attr' => ['placeholder' => 'user.username.placeholder'], 'empty_data' => '',
'disabled' => !$this->security->isGranted('edit_username', $entity), ]) 'label' => $this->trans->trans('user.username.label'),
'attr' => ['placeholder' => $this->trans->trans('user.username.placeholder')],
'disabled' => !$this->security->isGranted('edit_username', $entity),
])
->add('group', StructuralEntityType::class, ['class' => Group::class, ->add('group', StructuralEntityType::class, [
'required' => false, 'label' => 'group.label', 'disable_not_selectable' => true, 'class' => Group::class,
'required' => false,
'label' => $this->trans->trans('group.label'),
'disable_not_selectable' => true,
'disabled' => !$this->security->isGranted('change_group', $entity), ]) 'disabled' => !$this->security->isGranted('change_group', $entity), ])
->add('first_name', TextType::class, ['empty_data' => '', 'label' => 'user.firstName.label', ->add('first_name', TextType::class, [
'attr' => ['placeholder' => 'user.firstName.placeholder'], 'required' => false, 'empty_data' => '',
'disabled' => !$this->security->isGranted('edit_infos', $entity), ]) 'label' => $this->trans->trans('user.firstName.label'),
'attr' => ['placeholder' => $this->trans->trans('user.firstName.placeholder')], 'required' => false,
'disabled' => !$this->security->isGranted('edit_infos', $entity),
])
->add('last_name', TextType::class, ['empty_data' => '', 'label' => 'user.lastName.label', ->add('last_name', TextType::class, [
'attr' => ['placeholder' => 'user.lastName.placeholder'], 'required' => false, 'empty_data' => '',
'disabled' => !$this->security->isGranted('edit_infos', $entity), ]) 'label' => $this->trans->trans('user.lastName.label'),
'attr' => ['placeholder' => $this->trans->trans('user.lastName.placeholder')],
'required' => false,
'disabled' => !$this->security->isGranted('edit_infos', $entity),
])
->add('email', TextType::class, ['empty_data' => '', 'label' => 'user.email.label', ->add('email', TextType::class, [
'attr' => ['placeholder' => 'user.email.placeholder'], 'required' => false, 'empty_data' => '',
'label' => $this->trans->trans('user.email.label'),
'attr' => ['placeholder' => $this->trans->trans('user.email.placeholder')],
'required' => false,
'disabled' => !$this->security->isGranted('edit_infos', $entity), ]) 'disabled' => !$this->security->isGranted('edit_infos', $entity), ])
->add('department', TextType::class, ['empty_data' => '', 'label' => 'user.department.label', ->add('department', TextType::class, [
'attr' => ['placeholder' => 'user.department.placeholder'], 'required' => false, 'empty_data' => '',
'disabled' => !$this->security->isGranted('edit_infos', $entity), ]) 'label' => $this->trans->trans('user.department.label'),
'attr' => ['placeholder' => $this->trans->trans('user.department.placeholder')],
'required' => false,
'disabled' => !$this->security->isGranted('edit_infos', $entity),
])
; ;
/*->add('comment', CKEditorType::class, ['required' => false, /*->add('comment', CKEditorType::class, ['required' => false,
@ -96,9 +119,13 @@ class UserAdminForm extends AbstractType
$this->additionalFormElements($builder, $options, $entity); $this->additionalFormElements($builder, $options, $entity);
//Buttons //Buttons
$builder->add('save', SubmitType::class, ['label' => $is_new ? 'entity.create' : 'entity.edit.save', $builder->add('save', SubmitType::class, [
'attr' => ['class' => $is_new ? 'btn-success' : '']]) 'label' => $is_new ? $this->trans->trans('user.create') : $this->trans->trans('user.edit.save'),
->add('reset', ResetType::class, ['label' => 'entity.edit.reset']); 'attr' => ['class' => $is_new ? 'btn-success' : '']
])
->add('reset', ResetType::class, [
'label' => $this->trans->trans('entity.edit.reset')
]);
} }
protected function additionalFormElements(FormBuilderInterface $builder, array $options, NamedDBElement $entity) protected function additionalFormElements(FormBuilderInterface $builder, array $options, NamedDBElement $entity)

View file

@ -14,40 +14,64 @@ use Symfony\Component\Form\Extension\Core\Type\TimezoneType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Security\Core\Security; use Symfony\Component\Security\Core\Security;
use Symfony\Contracts\Translation\TranslatorInterface;
class UserSettingsType extends AbstractType class UserSettingsType extends AbstractType
{ {
protected $security; protected $security;
public function __construct(Security $security) protected $trans;
public function __construct(Security $security, TranslatorInterface $trans)
{ {
$this->security = $security; $this->security = $security;
$this->trans = $trans;
} }
public function buildForm(FormBuilderInterface $builder, array $options) public function buildForm(FormBuilderInterface $builder, array $options)
{ {
$builder $builder
->add('name', TextType::class, ['label' => 'user.username.label', ->add('name', TextType::class, [
'disabled' => !$this->security->isGranted('edit_username', $options['data']), ]) 'label' => $this->trans->trans('user.username.label'),
->add('first_name', TextType::class, ['required' => false, 'disabled' => !$this->security->isGranted('edit_username', $options['data']),
'label' => 'user.firstName.label', ])
'disabled' => !$this->security->isGranted('edit_infos', $options['data']), ]) ->add('first_name', TextType::class, [
->add('last_name', TextType::class, ['required' => false, 'required' => false,
'label' => 'user.lastName.label', 'label' => $this->trans->trans('user.firstName.label'),
'disabled' => !$this->security->isGranted('edit_infos', $options['data']), ]) 'disabled' => !$this->security->isGranted('edit_infos', $options['data']),
->add('department', TextType::class, ['required' => false, ])
'label' => 'user.department.label', ->add('last_name', TextType::class, [
'disabled' => !$this->security->isGranted('edit_infos', $options['data']), ]) 'required' => false,
->add('email', EmailType::class, ['required' => false, 'label' => $this->trans->trans('user.lastName.label'),
'label' => 'user.email.label', 'disabled' => !$this->security->isGranted('edit_infos', $options['data']),
'disabled' => !$this->security->isGranted('edit_infos', $options['data']), ]) ])
->add('language', LocaleType::class, ['required' => false, ->add('department', TextType::class, [
'attr' => ['class' => 'selectpicker', 'data-live-search' => true], 'placeholder' => 'user_settings.language.placeholder', 'label' => 'user.language_select', ]) 'required' => false,
->add('timezone', TimezoneType::class, ['required' => false, 'label' => $this->trans->trans('user.department.label'),
'disabled' => !$this->security->isGranted('edit_infos', $options['data']),
])
->add('email', EmailType::class, [
'required' => false,
'label' => $this->trans->trans('user.email.label'),
'disabled' => !$this->security->isGranted('edit_infos', $options['data']),
])
->add('language', LocaleType::class, [
'required' => false,
'attr' => ['class' => 'selectpicker', 'data-live-search' => true], 'attr' => ['class' => 'selectpicker', 'data-live-search' => true],
'placeholder' => 'user_settings.timezone.placeholder', 'label' => 'user.timezone.label', ]) 'placeholder' => $this->trans->trans('user_settings.language.placeholder'),
->add('theme', ChoiceType::class, ['required' => false, 'label' => $this->trans->trans('user.language_select'),
'placeholder' => 'user_settings.theme.placeholder', 'label' => 'user.theme.label', ]) ])
->add('timezone', TimezoneType::class, [
'required' => false,
'attr' => ['class' => 'selectpicker', 'data-live-search' => true],
'placeholder' => $this->trans->trans('user_settings.timezone.placeholder'),
'label' => $this->trans->trans('user.timezone.label'),
])
->add('theme', ChoiceType::class, [
'required' => false,
'placeholder' => $this->trans->trans('user_settings.theme.placeholder'),
'label' => $this->trans->trans('user.theme.label'),
])
//Buttons //Buttons
->add('save', SubmitType::class, ['label' => 'save']) ->add('save', SubmitType::class, ['label' => 'save'])