When setting up an entity bundle to be translatable, people have a choice of making each field translatable or not.

When a node gets an error for example because you try to save a node with required fields.
The label name is used in the error message as "@name is required".

Because content translation is putting (all languages) after the label this is also appearing in the error message.
So the error will be: "Field 1 (all languages) field is required."
But the current message is "Field 1 <span class="translation-entity-all-languages">(all languages)</span> field is required."

Problem: HTML is not rendered well in the error message.
Screenshot of wrong error message

Issue fork drupal-2899338

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Martijn de Wit created an issue. See original summary.

martijn de wit’s picture

Issue summary: View changes
martijn de wit’s picture

Title: Wrong render of HTML from label when field is shared across languages in error messasge » Wrong render of HTML from label when field is shared across languages in error message
martijn de wit’s picture

Issue summary: View changes

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

falco010’s picture

Created a patch that removes the span HTML. Does anyone know if this HTML is needed for anything? I could not find any code that is using the 'translation-entity-all-languages' class.

falco010’s picture

StatusFileSize
new901 bytes
martijn de wit’s picture

martijn de wit’s picture

@jonathan, Yes I think if everything is rendered by #markup there will be no issue any more. Didn't test is yet.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

stockticker’s picture

Version: 8.6.x-dev » 8.8.x-dev
StatusFileSize
new1.1 KB

I had a similar issue recently on one of the projects.
Attaching a patch.

I.e. HTML markup is still being escaped for the validations errors (so issues above do not resolve this problem)

martijn de wit’s picture

Version: 8.8.x-dev » 8.9.x-dev
martijn de wit’s picture

Status: Active » Needs review
martijn de wit’s picture

Version: 8.9.x-dev » 8.8.x-dev

sry... I think I was sleeping while changing the version...

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

cchiste’s picture

Version: 8.9.x-dev » 9.2.x-dev

Patch applies and works for inline errors in Drupal 9.2.x

cchiste’s picture

I was still noticing raw html in error messages at the top of the page and decided to track this down to the source. Submitted patch formats the combined title and translation hint suffix for html display.

feuerwagen’s picture

Status: Needs review » Needs work
Issue tags: +Bug Smash Initiative, +Needs tests

Thanks for the patch. Some nitpicks:

  1. +++ b/core/modules/content_translation/src/ContentTranslationHandler.php
    @@ -414,9 +415,9 @@ public function entityFormAlter(array &$form, FormStateInterface $form_state, En
    -          $this->getTranslationAccess($entity, 'delete')->isAllowed() ||
    -          ($entity->access('delete') && $this->entityType->hasLinkTemplate('delete-form'))
    -        );
    +            $this->getTranslationAccess($entity, 'delete')->isAllowed() ||
    +            ($entity->access('delete') && $this->entityType->hasLinkTemplate('delete-form'))
    +          );
    

    Unrelated formatting change.

  2. +++ b/core/modules/content_translation/src/ContentTranslationHandler.php
    @@ -648,6 +649,8 @@ protected function addTranslatabilityClue(&$element) {
    +      $formatted_title = new FormattableMarkup($element['#title'], []);
    +      $element['#title'] = $formatted_title;
    

    This can be one line.

Other than that, I'm pretty sure this needs a test to make sure that HTML in the field label is rendered correctly in the error message. What I'm not sure about: Is the translation hint the only place where HTML is added to the field label? Or can we find a more general approach to this?

ankithashetty’s picture

StatusFileSize
new1.07 KB
new1.57 KB

Addressed the changes specified in #20.1 and #20.2, thanks!

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.1.10 (June 4, 2021) and Drupal 9.2.10 (November 24, 2021) were the last bugfix releases of those minor version series. Drupal 9 bug reports should be targeted for the 9.3.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

artsays made their first commit to this issue’s fork.

jonathan1055’s picture

Issue summary: View changes

Fixed issue summary to correctly show the < and >

kumudb’s picture

StatusFileSize
new476.94 KB

It appears that this issue has been resolved in the latest version of Drupal 11. I have tested the scenario and verified that the error message no longer includes the "(all languages)" suffix.

I have attached a screenshot for reference. Given that the problem is no longer present, I believe we can close this issue.

Thank you!

pobster’s picture

Version: 11.x-dev » 10.3.x-dev
StatusFileSize
new1.11 KB

Not everyone is on 11.x yet... This is rerolled for 10.3.x.

quietone’s picture

Version: 10.3.x-dev » 11.x-dev
Issue tags: +Needs issue summary update, +Needs screenshots

Changes are made on on 11.x (our main development branch) first, and are then back ported as needed according to the Core change policies.

This is changing a user facing error message so will need before and after screenshots. They should be available to reviewers/committers from the Issue Summary.

This also needs an issue summary update, add the standard issue template and complete the 'Problem/Motivation', 'Steps to reproduce', and 'Proposed resolution' sections. Leave the other sections empty for use by other contributors.

pobster’s picture

Version: 11.x-dev » 10.4.x-dev

https://www.drupal.org/project/drupal/issues/2899338#comment-15774058

It appears that this issue has been resolved in the latest version of Drupal 11.

quietone’s picture

Status: Needs work » Closed (won't fix)

@pobster, thanks for repeating that this is fixed in D11. I couldn't find the issue where this was fixed but it wasn't backported to D10.

Thanks everyone for working on this issue. The current error message should render the HTML correctly, However, this

I agree that the current string is somewhat misleading, and the suggested change would improve it. However, Drupal 10 is in maintenance mode and this issue doesn't meet the criteria for an allowed change in a maintenance minor,

Therefor, I am closing this issue as won't fix.