Entity builder method is not invoked, plural is not saved

Created on 3 July 2025, 4 days ago

Problem/Motivation

The entity builder is not invoked.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇭🇺Hungary Gábor Hojtsy Hungary

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @Gábor Hojtsy
  • Merge request !13Convert callable to array → (Merged) created by Gábor Hojtsy
  • AFAICT, entity builders are only invoked on a request with form input, not on the initial form build. Populating the field on the initial build probably needs the #default_value to be set or similar?

  • 🇭🇺Hungary Gábor Hojtsy Hungary

    @godotislate: I don't believe that is a problem, we are testing whether on form submission the entity gets the language, and it appears it does not (likely the third party setting is not saved).

  • @gábor hojtsy: I see now that the entity_builder is supposed to populate the third party setting on the add form, before going to the edit form in the test.

    The issue about the edit form field not being populated correctly isn't an issue with the entity builder not being invoked, it's with this logic in PluralFormulaLanguageFormBase::form():

    // Pick previous plural formula if editing an existing language.
        $plural_formula = '';
        if (isset($form['langcode']['#value'])) {
          $editingLangcode = $form['langcode']['#value'];
          /** @var \Drupal\language\ConfigurableLanguageInterface $language */
          $language = $form_state->getFormObject()->getEntity();
          $plural_formula = $language->getThirdPartySetting('l10n_pconfig', 'formula');
        }
    

    In Drupal\language\Form\LanguageFormBase::commonForm(), this is how the form is built:

    if ($language->getId()) {
          $form['langcode_view'] = [
            '#type' => 'item',
            '#title' => $this->t('Language code'),
            '#markup' => $language->id(),
          ];
        }
        else {
          $form['langcode'] = [
            '#type' => 'textfield',
            '#title' => $this->t('Language code'),
            '#maxlength' => 12,
            '#required' => TRUE,
            '#default_value' => '',
            '#disabled' => FALSE,
            '#description' => $this->t('Use language codes as <a href=":w3ctags">defined by the W3C</a> for interoperability. <em>Examples: "en", "en-gb" and "zh-hant".</em>', [':w3ctags' => 'https://www.w3.org/International/articles/language-tags/']),
          ];
        }
    

    So isset($form['langcode']['#value']) in PluralFormulaLanguageFormBase::form() is FALSE, and the third party settings are not loaded to populate the form value.

  • 🇭🇺Hungary Gábor Hojtsy Hungary

    That works beautifully, thanks!

  • Pipeline finished with Skipped
    3 days ago
    #539156
Production build 0.71.5 2024