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\FormBuilderInterface;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Translation\Reader\TranslationReader;
use Symfony\Contracts\Translation\TranslatorInterface;
class BaseEntityAdminForm extends AbstractType
{
protected $security;
protected $params;
protected $trans;
public function __construct(Security $security, ParameterBagInterface $params)
public function __construct(Security $security, ParameterBagInterface $params, TranslatorInterface $trans)
{
$this->security = $security;
$this->params = $params;
$this->trans = $trans;
}
@ -67,26 +71,30 @@ class BaseEntityAdminForm extends AbstractType
$is_new = $entity->getID() === null;
$builder
->add('name', TextType::class, ['empty_data' => '', 'label' => 'name.label',
'attr' => ['placeholder' => 'part.name.placeholder'],
->add('name', TextType::class, ['empty_data' => '', 'label' => $this->trans->trans('name.label'),
'attr' => ['placeholder' => $this->trans->trans('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',
'required' => false, 'label' => $this->trans->trans('parent.label'),
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity), ])
->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) ])
->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)]);
$this->additionalFormElements($builder, $options, $entity);
//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' : ''],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity)])
->add('reset', ResetType::class, ['label' => 'entity.edit.reset',

View file

@ -45,35 +45,47 @@ class CategoryAdminForm extends BaseEntityAdminForm
$is_new = $entity->getID() === null;
$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'),
'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,
'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)]);
$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)]);
$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)]);
$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)]);
$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)]);
$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)]);
$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)]);
}
}

View file

@ -48,39 +48,48 @@ class CompanyForm extends BaseEntityAdminForm
{
$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),
'attr' => ['placeholder' => 'company.address.placeholder'], 'required' => false,
'attr' => ['placeholder' => $this->trans->trans('company.edit.address.placeholder')], 'required' => false,
'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),
'attr' => ['placeholder' => 'company.phone_number.placeholder'], 'required' => false,
'attr' => ['placeholder' => $this->trans->trans('company.edit.phone_number.placeholder')],
'required' => false,
'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),
'attr' => ['placeholder' => 'company.fax_number.placeholder'], 'required' => false,
'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),
'attr' => ['placeholder' => 'company.email.placeholder'], 'required' => false,
'attr' => ['placeholder' => $this->trans->trans('company.edit.email.placeholder')], 'required' => false,
'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),
'attr' => ['placeholder' => 'company.website.placeholder'], 'required' => false,
'attr' => ['placeholder' => $this->trans->trans('company.edit.website.placeholder')], 'required' => false,
'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),
'attr' => ['placeholder' => 'company.auto_product_url.placeholder'], 'required' => false,
'attr' => ['placeholder' => $this->trans->trans('company.edit.auto_product_url.placeholder')],
'required' => false,
'empty_data' => ''
]);
}

View file

@ -44,15 +44,17 @@ class CurrencyAdminForm extends BaseEntityAdminForm
{
$is_new = $entity->getID() === null;
$builder->add('iso_code', CurrencyType::class , ['required' => true,
$builder->add('iso_code', CurrencyType::class, [
'required' => false,
'label' => 'currency.iso_code.label',
'label' => $this->trans->trans('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' => 'currency.exchange_rate.label', 'currency' => $this->params->get('default_currency'),
$builder->add('exchange_rate', MoneyType::class, [
'required' => false,
'label' => $this->trans->trans('currency.edit.exchange_rate'),
'currency' => $this->params->get('default_currency'),
'scale' => 6,
'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\Form\Type\StructuralEntityType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Bundle\MakerBundle\Str;
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\FormBuilderInterface;
use Symfony\Component\Security\Core\Security;
use Symfony\Contracts\Translation\TranslatorInterface;
class ImportType extends AbstractType
{
protected $security;
protected $trans;
public function __construct(Security $security)
public function __construct(Security $security, TranslatorInterface $trans)
{
$this->security = $security;
$this->trans = $trans;
}
public function buildForm(FormBuilderInterface $builder, array $options)
@ -60,31 +64,42 @@ class ImportType extends AbstractType
$data = $options['data'];
//Disable import if user is not allowed to create elements.
$entity = new $data['entity_class'];
$entity = new $data['entity_class']();
$perm_name = "create";
$disabled = ! $this->security->isGranted($perm_name, $entity);
$builder
->add('format', ChoiceType::class, ['choices' =>
['JSON' => 'json', 'XML' => 'xml','CSV'=>'csv' ,'YAML' => 'yaml'], 'label' => 'export.format',
->add('format', ChoiceType::class, [
'choices' => ['JSON' => 'json', 'XML' => 'xml','CSV' => 'csv' ,'YAML' => 'yaml'],
'label' => $this->trans->trans('export.format'),
'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]);
if($entity instanceof StructuralDBElement) {
$builder->
add('parent', EntityType::class, ['class' => $data['entity_class'], 'choice_label' => 'full_path',
'attr' => ['class' => 'selectpicker', 'data-live-search' => true], 'required' => false,
'label' => 'parent.label', 'disabled' => $disabled]);
if ($entity instanceof StructuralDBElement) {
$builder->add('parent', StructuralEntityType::class, [
'class' => $data['entity_class'],
'required' => false,
'label' => $this->trans->trans('parent.label'),
'disabled' => $disabled
]);
}
$builder->add('file', FileType::class, ['label' => 'import.file',
'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,
'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,
'label' => 'import.abort_on_validation', 'help'=> 'import.abort_on_validation.help',
'label_attr'=> ['class' => 'checkbox-custom'], 'disabled' => $disabled])
'label' => $this->trans->trans('import.abort_on_validation'),
'help' => $this->trans->trans('import.abort_on_validation.help'),
'label_attr' => ['class' => 'checkbox-custom'], 'disabled' => $disabled])
//Buttons
->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\Form\Type\StructuralEntityType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
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\FormBuilderInterface;
use Symfony\Component\Security\Core\Security;
use Symfony\Contracts\Translation\TranslatorInterface;
class MassCreationForm extends AbstractType
{
protected $security;
protected $translator;
public function __construct(Security $security)
public function __construct(Security $security, TranslatorInterface $translator)
{
$this->security = $security;
$this->translator = $translator;
}
public function buildForm(FormBuilderInterface $builder, array $options)
@ -64,18 +68,26 @@ class MassCreationForm extends AbstractType
$disabled = ! $this->security->isGranted($perm_name, $entity);
$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,
'attr' => ['placeholder' => 'mass_creation.lines.placeholder', 'rows' => 10]]);
'attr' => [
'placeholder' => $this->translator->trans('mass_creation.lines.placeholder'),
'rows' => 10
]
]);
if ($entity instanceof StructuralDBElement) {
$builder->
add('parent', EntityType::class, ['class' => $data['entity_class'], 'choice_label' => 'full_path',
'attr' => ['class' => 'selectpicker', 'data-live-search' => true], 'required' => false,
'label' => 'parent.label', 'disabled' => $disabled]);
$builder->add('parent', StructuralEntityType::class, [
'class' => $data['entity_class'],
'required' => false,
'label' => $this->translator->trans('parent.label'),
'disabled' => $disabled]);
}
$builder
//Buttons
->add('create', SubmitType::class, ['label' => 'mass_creation.btn', 'disabled' => $disabled]);
$builder->add('create', SubmitType::class, [
'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;
$builder->add('is_integer', CheckboxType::class, ['required' => false,
'label' => 'measurement_unit.is_integer.label', 'help' => 'measurement_unit.is_integer.help',
'label_attr'=> ['class' => 'checkbox-custom'],
'label' => $this->trans->trans('measurement_unit.edit.is_integer'),
'help' => $this->trans->trans('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' => 'measurement_unit.use_si_prefix.label', 'help' => 'measurement_unit.use_si_prefix.help',
'label_attr'=> ['class' => 'checkbox-custom'],
'label' => $this->trans->trans('measurement_unit.edit.use_si_prefix'),
'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)]);
$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)]);
}
}

View file

@ -46,23 +46,31 @@ class StorelocationAdminForm extends BaseEntityAdminForm
{
$is_new = $entity->getID() === null;
$builder->add('is_full', CheckboxType::class, ['required' => false,
'label' => 'storelocation.is_full.label', 'help' => 'storelocation.is_full.help',
'label_attr'=> ['class' => 'checkbox-custom'],
$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_attr' => ['class' => 'checkbox-custom'],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity)]);
$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'],
$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_attr' => ['class' => 'checkbox-custom'],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity)]);
$builder->add('only_single_part', CheckboxType::class, ['required' => false,
'label' => 'storelocation.only_single_part.label', 'help' => 'storelocation.only_single_part.help',
'label_attr'=> ['class' => 'checkbox-custom'],
$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_attr' => ['class' => 'checkbox-custom'],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity)]);
$builder->add('storage_type', StructuralEntityType::class, ['required' => false,
'label' => 'storelocation.storage_type.label', 'help' => 'storelocation.storage_type.help',
$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,
'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\FormBuilderInterface;
class SupplierForm extends BaseEntityAdminForm
class SupplierForm extends CompanyForm
{
protected function additionalFormElements(FormBuilderInterface $builder, array $options, NamedDBElement $entity)
{
$is_new = $entity->getID() === null;
$builder->add('address', TextareaType::class, ['label' => 'company.address.label',
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity),
'attr' => ['placeholder' => 'company.address.placeholder'], 'required' => false,
'empty_data' => ''
]);
parent::additionalFormElements($builder, $options, $entity);
$builder->add('phone_number', TelType::class, ['label' => 'company.phone_number.label',
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity),
'attr' => ['placeholder' => 'company.phone_number.placeholder'], 'required' => false,
'empty_data' => ''
]);
$builder->add('fax_number', TelType::class, ['label' => 'company.fax_number.label',
'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' => '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,
$builder->add('default_currency', StructuralEntityType::class, [
'class' => Currency::class,
'required' => false,
'label' => $this->trans->trans('supplier.edit.default_currency'),
'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',
$builder->add('shipping_costs', MoneyType::class, [
'required' => false,
'currency' => $this->params->get('default_currency'),
'scale' => 3,
'label' => $this->trans->trans('supplier.shipping_costs.label'),
'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\Validator\Constraints\File;
use Symfony\Component\Validator\Constraints\Url;
use Symfony\Contracts\Translation\TranslatorInterface;
class AttachmentFormType extends AbstractType
{
protected $attachment_helper;
protected $trans;
public function __construct(AttachmentHelper $attachmentHelper)
public function __construct(AttachmentHelper $attachmentHelper, TranslatorInterface $trans)
{
$this->attachment_helper = $attachmentHelper;
$this->trans = $trans;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('name', TextType::class,
[
'label' => 'attachment.edit.name'
$builder->add('name', TextType::class, [
'label' => $this->trans->trans('attachment.edit.name')
])
->add('attachment_type', StructuralEntityType::class, [
'label' => 'attachment.edit.attachment_type',
'label' => $this->trans->trans('attachment.edit.attachment_type'),
'class' => AttachmentType::class,
'disable_not_selectable' => true,
]);
$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'],
'label_attr' => ['class' => 'checkbox-custom']]);
$builder->add('url', UrlType::class, [
'label' => 'attachment.edit.url',
'label' => $this->trans->trans('attachment.edit.url'),
'required' => false,
'constraints' => [
new Url()
@ -82,7 +84,7 @@ class AttachmentFormType extends AbstractType
]);
$builder->add('file', FileType::class, [
'label' => 'attachment.edit.file',
'label' => $this->trans->trans('attachment.edit.file'),
'mapped' => false,
'required' => 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\FormEvents;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Contracts\Translation\TranslatorInterface;
use function foo\func;
class OrderdetailType extends AbstractType
{
protected $trans;
public function __construct(TranslatorInterface $trans)
{
$this->trans = $trans;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
/** @var Orderdetail $orderdetail */
$orderdetail = $builder->getData();
$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,
'empty_data' => ""
]);
$builder->add('supplier', StructuralEntityType::class, [
'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, [
'required' => false,
'empty_data' => "",
'label' => 'orderdetails.edit.url'
'label' => $this->trans->trans('orderdetails.edit.url')
]);
$builder->add('obsolete', CheckboxType::class, [
'required' => false,
'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
$builder
->add('name', TextType::class, ['empty_data' => '', 'label' => 'name.label',
'attr' => ['placeholder' => 'part.name.placeholder'],
'disabled' => !$this->security->isGranted('name.edit', $part), ])
->add('description', CKEditorType::class, ['required' => false, 'empty_data' => '',
'label' => 'description.label', 'help' => 'bbcode.hint', 'config_name' => 'description_config',
'attr' => ['placeholder' => 'part.description.placeholder', 'rows' => 2],
'disabled' => !$this->security->isGranted('description.edit', $part) ])
->add('minAmount', SIUnitType::class,
['attr' => ['min' => 0, 'placeholder' => 'part.mininstock.placeholder'], 'label' => 'mininstock.label',
->add('name', TextType::class, [
'empty_data' => '',
'label' => $this->trans->trans('part.edit.name'),
'attr' => ['placeholder' => $this->trans->trans('part.edit.name.placeholder')],
'disabled' => !$this->security->isGranted('name.edit', $part),
])
->add('description', CKEditorType::class, [
'required' => false,
'empty_data' => '',
'label' => $this->trans->trans('part.edit.description'),
'config_name' => 'description_config',
'attr' => ['placeholder' => $this->trans->trans('part.edit.description.placeholder'), 'rows' => 2],
'disabled' => !$this->security->isGranted('description.edit', $part)
])
->add('minAmount', SIUnitType::class, [
'attr' => ['min' => 0, 'placeholder' => $this->trans->trans('part.editmininstock.placeholder')],
'label' => $this->trans->trans('part.edit.mininstock'),
'measurement_unit' => $part->getPartUnit(),
'disabled' => !$this->security->isGranted('mininstock.edit', $part), ])
->add('category', StructuralEntityType::class, ['class' => Category::class,
'label' => 'category.label', 'disable_not_selectable' => true,
'disabled' => !$this->security->isGranted('move', $part), ])
->add('footprint', StructuralEntityType::class, ['class' => Footprint::class, 'required' => false,
'label' => 'footprint.label', 'disable_not_selectable' => true,
'disabled' => !$this->security->isGranted('move', $part), ])
->add('tags', TextType::class, ['required' => false, 'label' => 'part.tags', 'empty_data' => "",
'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'],
'disabled' => !$this->security->isGranted('edit', $part) ]);
'disabled' => !$this->security->isGranted('edit', $part)
]);
//Manufacturer section
$builder->add('manufacturer', StructuralEntityType::class, ['class' => Manufacturer::class,
'required' => false, 'label' => 'manufacturer.label', 'disable_not_selectable' => true,
'disabled' => !$this->security->isGranted('manufacturer.edit', $part), ])
->add('manufacturer_product_url', UrlType::class, ['required' => false, 'empty_data' => '',
'label' => 'manufacturer_url.label',
'disabled' => !$this->security->isGranted('manufacturer.edit', $part), ])
->add('manufacturer_product_number', TextType::class, ['required' => false,
'empty_data' => '', 'label' => 'part.mpn',
$builder->add('manufacturer', StructuralEntityType::class, [
'class' => Manufacturer::class,
'required' => false,
'label' => $this->trans->trans('part.edit.manufacturer.label'),
'disable_not_selectable' => true,
'disabled' => !$this->security->isGranted('manufacturer.edit', $part)
])
->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)])
->add('manufacturing_status', ChoiceType::class, [
'label' => 'part.manufacturing_status',
'label' => $this->trans->trans('part.edit.manufacturing_status'),
'choices' => $status_choices,
'required' => false,
'disabled' => !$this->security->isGranted('manufacturer.edit', $part)
]);
//Advanced section
$builder->add('needsReview', CheckboxType::class, ['label_attr'=> ['class' => 'checkbox-custom'],
'required' => false, 'label' => 'part.edit.needs_review'])
->add('favorite', CheckboxType::class, ['label_attr'=> ['class' => 'checkbox-custom'],
'required' => false, 'label' => 'part.edit.is_favorite'])
->add('mass', SIUnitType::class, ['unit' => 'g',
'label' => 'part.mass', 'required' => false])
->add('partUnit', StructuralEntityType::class, ['class'=> MeasurementUnit::class,
'required' => false, 'disable_not_selectable' => true, 'label' => 'part.partUnit']);
$builder->add('needsReview', CheckboxType::class, [
'label_attr' => ['class' => 'checkbox-custom'],
'required' => false,
'label' => $this->trans->trans('part.edit.needs_review')
])
->add('favorite', CheckboxType::class, [
'label_attr' => ['class' => 'checkbox-custom'],
'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
$builder->add('comment', CKEditorType::class, ['required' => false,
'label' => 'comment.label', 'attr' => ['rows' => 4], 'help' => 'bbcode.hint',
'disabled' => !$this->security->isGranted('comment.edit', $part), 'empty_data' => '']);
$builder->add('comment', CKEditorType::class, [
'required' => false,
'label' => $this->trans->trans('part.edit.comment'),
'attr' => ['rows' => 4],
'disabled' => !$this->security->isGranted('comment.edit', $part), 'empty_data' => ''
]);
//Part Lots section
$builder->add('partLots', CollectionType::class, [
@ -169,7 +214,7 @@ class PartBaseType extends AbstractType
$builder->add('master_picture_attachment', EntityType::class, [
'required' => false,
'label' => 'part.edit.master_attachment',
'label' => $this->trans->trans('part.edit.master_attachment'),
'class' => PartAttachment::class,
'attr' => ['class' => 'selectpicker'],
'choice_attr' => function ($choice, $key, $value) {
@ -200,8 +245,8 @@ class PartBaseType extends AbstractType
$builder
//Buttons
->add('save', SubmitType::class, ['label' => 'part.edit.save'])
->add('reset', ResetType::class, ['label' => 'part.edit.reset']);
->add('save', SubmitType::class, ['label' => $this->trans->trans('part.edit.save')])
->add('reset', ResetType::class, ['label' => $this->trans->trans('part.edit.reset')]);
}
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\FormInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Contracts\Translation\TranslatorInterface;
use function GuzzleHttp\Promise\queue;
class PartLotType extends AbstractType
{
protected $trans;
public function __construct(TranslatorInterface $trans)
{
$this->trans = $trans;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('description', TextType::class, ['label' => 'part_lot.edit.description',
'required' => false, 'empty_data' => "", 'attr' => ['class' => 'form-control-sm']]);
$builder->add('description', TextType::class, [
'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,
'label' => 'part_lot.edit.location',
'label' => $this->trans->trans('part_lot.edit.location'),
'required' => false,
'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, [
'measurement_unit' => $options['measurement_unit'],
'label' => 'part_lot.edit.amount',
'label' => $this->trans->trans('part_lot.edit.amount'),
'attr' => ['class' => 'form-control-sm']
]);
$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'],
'label_attr' => ['class' => 'checkbox-custom']]);
'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'],
'required' => false]);
'required' => false
]);
$builder->add('expirationDate', DateTimeType::class, [
'label' => 'part_lot.edit.expiration_date',
'label' => $this->trans->trans('part_lot.edit.expiration_date'),
'attr' => [],
'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'],
'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\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Contracts\Translation\TranslatorInterface;
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\FormBuilderInterface;
use Symfony\Component\Security\Core\Security;
use Symfony\Contracts\Translation\TranslatorInterface;
class UserAdminForm extends AbstractType
{
protected $security;
protected $trans;
public function __construct(Security $security)
public function __construct(Security $security, TranslatorInterface $trans)
{
$this->security = $security;
$this->trans = $trans;
}
@ -63,30 +66,50 @@ class UserAdminForm extends AbstractType
$is_new = $entity->getID() === null;
$builder
->add('name', TextType::class, ['empty_data' => '', 'label' => 'user.username.label',
'attr' => ['placeholder' => 'user.username.placeholder'],
'disabled' => !$this->security->isGranted('edit_username', $entity), ])
->add('name', TextType::class, [
'empty_data' => '',
'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,
'required' => false, 'label' => 'group.label', 'disable_not_selectable' => true,
->add('group', StructuralEntityType::class, [
'class' => Group::class,
'required' => false,
'label' => $this->trans->trans('group.label'),
'disable_not_selectable' => true,
'disabled' => !$this->security->isGranted('change_group', $entity), ])
->add('first_name', TextType::class, ['empty_data' => '', 'label' => 'user.firstName.label',
'attr' => ['placeholder' => 'user.firstName.placeholder'], 'required' => false,
'disabled' => !$this->security->isGranted('edit_infos', $entity), ])
->add('first_name', TextType::class, [
'empty_data' => '',
'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',
'attr' => ['placeholder' => 'user.lastName.placeholder'], 'required' => false,
'disabled' => !$this->security->isGranted('edit_infos', $entity), ])
->add('last_name', TextType::class, [
'empty_data' => '',
'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',
'attr' => ['placeholder' => 'user.email.placeholder'], 'required' => false,
->add('email', TextType::class, [
'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), ])
->add('department', TextType::class, ['empty_data' => '', 'label' => 'user.department.label',
'attr' => ['placeholder' => 'user.department.placeholder'], 'required' => false,
'disabled' => !$this->security->isGranted('edit_infos', $entity), ])
->add('department', TextType::class, [
'empty_data' => '',
'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,
@ -96,9 +119,13 @@ class UserAdminForm extends AbstractType
$this->additionalFormElements($builder, $options, $entity);
//Buttons
$builder->add('save', SubmitType::class, ['label' => $is_new ? 'entity.create' : 'entity.edit.save',
'attr' => ['class' => $is_new ? 'btn-success' : '']])
->add('reset', ResetType::class, ['label' => 'entity.edit.reset']);
$builder->add('save', SubmitType::class, [
'label' => $is_new ? $this->trans->trans('user.create') : $this->trans->trans('user.edit.save'),
'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)

View file

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