diff --git a/src/Form/ParameterType.php b/src/Form/ParameterType.php index 413df3e4..e8e6db1c 100644 --- a/src/Form/ParameterType.php +++ b/src/Form/ParameterType.php @@ -24,10 +24,23 @@ declare(strict_types=1); namespace App\Form; use App\Entity\Parameters\AbstractParameter; +use App\Entity\Parameters\AttachmentTypeParameter; +use App\Entity\Parameters\CategoryParameter; +use App\Entity\Parameters\CurrencyParameter; +use App\Entity\Parameters\DeviceParameter; +use App\Entity\Parameters\FootprintParameter; +use App\Entity\Parameters\GroupParameter; +use App\Entity\Parameters\ManufacturerParameter; +use App\Entity\Parameters\PartParameter; +use App\Entity\Parameters\StorelocationParameter; +use App\Entity\Parameters\SupplierParameter; +use App\Entity\Parts\MeasurementUnit; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\NumberType; use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormBuilderInterface; +use Symfony\Component\Form\FormInterface; +use Symfony\Component\Form\FormView; use Symfony\Component\OptionsResolver\OptionsResolver; class ParameterType extends AbstractType @@ -117,6 +130,32 @@ class ParameterType extends AbstractType ]); } + public function finishView(FormView $view, FormInterface $form, array $options) + { + //By default use part parameters for autocomplete + $view->vars['type'] = 'part'; + + $map = [ + PartParameter::class => 'part', + AttachmentTypeParameter::class => 'attachment_type', + CategoryParameter::class => 'category', + CurrencyParameter::class => 'currency', + DeviceParameter::class => 'device', + FootprintParameter::class => 'footprint', + GroupParameter::class => 'group', + ManufacturerParameter::class => 'manufacturer', + MeasurementUnit::class => 'measurement_unit', + StorelocationParameter::class => 'storelocation', + SupplierParameter::class => 'supplier', + ]; + + if (isset($map[$options['data_class']])) { + $view->vars['type'] = $map[$options['data_class']]; + } + + parent::finishView($view, $form, $options); // TODO: Change the autogenerated stub + } + public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ diff --git a/templates/Parts/edit/edit_form_styles.html.twig b/templates/Parts/edit/edit_form_styles.html.twig index 77439f20..47b66476 100644 --- a/templates/Parts/edit/edit_form_styles.html.twig +++ b/templates/Parts/edit/edit_form_styles.html.twig @@ -68,7 +68,7 @@ {% block parameter_widget %} {% import 'components/collection_type.macro.html.twig' as collection %} -