ContentTranslationHandler::entityFormAlter overrides title

Created on 2 September 2025, about 2 months ago

Problem/Motivation

ContentTranslationHandler::entityFormAlter() has code that forcibly overrides the title of the edit form of entities, providing either a 'Create translation' or a label with the language attached. This is probably intended as a feature but it silently overrides and ignores whatever the developer sets as _title or _title_callback when creating a translatable custom entity. There's no documentation that I could find that mentions this.

Having this forced title means that TitleResolver (either the stock one or one the developer creates) is never called for this route, completely removing any usual way for the developer to determine the title for these forms.

  public function entityFormAlter(array &$form, FormStateInterface $form_state, EntityInterface $entity) {
    ...
    // Adjust page title to specify the current language being edited, if we
    // have at least one translation.
    $languages = $this->languageManager->getLanguages();
    if (isset($languages[$form_langcode]) && ($has_translations || $new_translation)) {
      $title = $this->entityFormTitle($entity);
      // When editing the original values display just the entity label.
      if ($is_translation) {
        $t_args = ['%language' => $languages[$form_langcode]->getName(), '%title' => $entity->label(), '@title' => $title];
        $title = $new_translation ? t('Create %language translation of %title', $t_args) : t('@title [%language translation]', $t_args);
      }
      $form['#title'] = $title;
    }

I would see some benefit in adding the language code or name to the existing title but very certainly not overriding it behind our back, without any chance of altering or disabling this behavior.

Steps to reproduce

  • add a custom entity
  • set it translatable
  • provide a title or a title callback with any title or you choice (could as simple as "???")
  • the set title will be replaced with the result of $entity->label()

Proposed resolution

Remove this whole override, or make it optional and opt-in.

🐛 Bug report
Status

Active

Version

11.2 🔥

Component

content_moderation.module

Created by

🇭🇺Hungary djg_tram

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

Comments & Activities

Production build 0.71.5 2024