Jump to content

Custom_field for AdminProduct page. (New method translation doesn't work)


REGE

Recommended Posts

Hello,

I added a test_field in /src/PrestaShopBundle/Form/Admin/Product/ProductInformation.php

public function buildForm(FormBuilderInterface $builder, array $options)
{
    . . .

    ->add('test_field', TranslateType::class, [
        'type' => FormType\TextType::class,
        'constraints' => [
            new Assert\Regex([
                'pattern' => '/[<>;=#{}]/',
                'match' => false,
            ]),
            new Assert\NotBlank(),
            new Assert\Length(['min' => 3, 'max' => 50]),
        ],
        'options' => [
            'attr' => [
                'placeholder' => $this->translator->trans('Enter your test text', [], 'Admin.Catalog.Feature'),
                'class' => 'edit js-edit',
                'counter' => 50,
            ],
            'required' => true,
        ],
        'locales' => $this->locales,
        'label' => $this->translator->trans('Test field', [], 'Admin.Catalog.Feature'),
    ])

   . . .
}

 

defined in  /src/PrestaShopBundle/Resources/views/Admin/Product/ProductPage/product.html.twig

{# PANEL ESSENTIALS #}
{% block product_panel_essentials %}
  {% set formQuantityShortcut = form.step1.qty_0_shortcut is defined ? form.step1.qty_0_shortcut : null  %}
  {{ include('@Product/ProductPage/Panels/essentials.html.twig', {
      . . .

      'formTestField': form.step1.test_field,

      . . .
    })
  }}
{% endblock %}

 

and set HTML in  /src/PrestaShopBundle/Resources/views/Admin/Product/ProductPage/Panels/essentials.html.twig

<div id="test_field" class="mb-3">
  <strong>{{ form_label(formTestField) }}</strong>
  {{ form_widget(formTestField) }}
</div>

 

The field is displayed correctly. It's for JS use only - it doesn't write to the database. However, I have a problem with the translation. It should be on the Admin.Catalog.Feature domain but it's not showing in the translation interface.

 

What am I doing wrong? How do I translate the label and placeholder for a newly added field to my language?

Link to comment
Share on other sites

  • 8 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...