Use the correct autocomplete type for non-part entities.

This commit is contained in:
Jan Böhmer 2022-09-05 17:38:47 +02:00
parent 34053f6591
commit 4d78f8d4e8
2 changed files with 40 additions and 1 deletions

View file

@ -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([

View file

@ -68,7 +68,7 @@
{% block parameter_widget %}
{% import 'components/collection_type.macro.html.twig' as collection %}
<tr {{ stimulus_controller('pages/parameters_autocomplete', {"url": url('typeahead_parameters', {"query": "__QUERY__", "type": "part"})}) }}>
<tr {{ stimulus_controller('pages/parameters_autocomplete', {"url": url('typeahead_parameters', {"query": "__QUERY__", "type": form.vars["type"]})}) }}>
<td>{{ form_widget(form.name, {"attr": {"data-pages--parameters-autocomplete-target": "name"}}) }}{{ form_errors(form.name) }}</td>
<td {{ stimulus_controller('pages/latex_preview') }}>{{ form_widget(form.symbol, {"attr": {"data-pages--parameters-autocomplete-target": "symbol", "data-pages--latex-preview-target": "input"}}) }}{{ form_errors(form.symbol) }}<span {{ stimulus_target('pages/latex_preview', 'preview') }}></span></td>
<td>{{ form_widget(form.value_min) }}{{ form_errors(form.value_min) }}</td>