Skip to content
Snippets Groups Projects

issue/3456149: Fixed translation string in ConfigFormBase

Open Pooja Sharma requested to merge issue/drupal-3456149:3456149-fix-translation-string into 11.x
3 unresolved threads

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
291 291 '@validation_error_message' => $violation->getMessage(),
292 292 ]);
293 293 }
294 return $this->t(implode("\n", $transformed_message_parts));
294 $transformed_message = implode("\n", $transformed_message_parts);
295 // We use \Drupal\Component\Render\FormattableMarkup directly here,
296 // rather than use t() to ensure proper handling of content and
297 // prevent unintended translation.
298 return new FormattableMarkup('%transformed_message', ['%transformed_message' => $transformed_message]);
  • Comment on lines +294 to +298

    This is going to wrap the message in em tags because of the percentage. I think this should be:

    Suggested change
    294 $transformed_message = implode("\n", $transformed_message_parts);
    295 // We use \Drupal\Component\Render\FormattableMarkup directly here,
    296 // rather than use t() to ensure proper handling of content and
    297 // prevent unintended translation.
    298 return new FormattableMarkup('%transformed_message', ['%transformed_message' => $transformed_message]);
    294 $transformed_message = implode("\n", $transformed_message_parts);
    295 // We use \Drupal\Component\Render\FormattableMarkup directly here,
    296 // rather than use t() to ensure proper handling of content and
    297 // prevent unintended translation.
    298 return new FormattableMarkup(implode("\n", $transformed_message_parts));

    But actually I think this would be even better if we did return Markup::create(implode("\n", $transformed_message_parts)); - also I think the return type could be MarkupInterface or \Stringable

    The comment should explain that this is safe because all input has been escaped by t() above.

  • Pooja Sharma changed this line in version 6 of the diff

    changed this line in version 6 of the diff

  • Please register or sign in to reply
  • Pooja Sharma added 1 commit

    added 1 commit

    • 6ee52743 - issue/3456149: Applied suggestions ConfigFormBase

    Compare with previous version

  • 276 277 * @param \Symfony\Component\Validator\ConstraintViolationListInterface $violations
    277 278 * The list of constraint violations that apply to this form element.
    278 279 *
    279 * @return \Drupal\Core\StringTranslation\TranslatableMarkup
    280 * @return \Drupal\Component\Render\MarkupInterface|string
    281 * The rendered HTML.
    280 282 */
    281 protected function formatMultipleViolationsMessage(string $form_element_name, array $violations): TranslatableMarkup {
    283 protected function formatMultipleViolationsMessage(string $form_element_name, array $violations): MarkupInterface|string {
  • Pooja Sharma added 1 commit

    added 1 commit

    • bcd7f310 - issue/3456149: Updated ConfigFormBase

    Compare with previous version

  • Pooja Sharma added 1 commit

    added 1 commit

    • 97d7e04c - issue/3456149: Applied suggestion ConfigFormBase

    Compare with previous version

  • Pooja Sharma added 1 commit

    added 1 commit

    • e32a769f - issue/3456149: Applied suggestions ConfigFormBase

    Compare with previous version

  • 276 277 * @param \Symfony\Component\Validator\ConstraintViolationListInterface $violations
    277 278 * The list of constraint violations that apply to this form element.
    278 279 *
    279 * @return \Drupal\Core\StringTranslation\TranslatableMarkup
    280 * @return \Drupal\Component\Render\MarkupInterface|\Stringable
    281 * The rendered HTML.
    280 282 */
    281 protected function formatMultipleViolationsMessage(string $form_element_name, array $violations): TranslatableMarkup {
    283 protected function formatMultipleViolationsMessage(string $form_element_name, array $violations): MarkupInterface|\Stringable {
    • Comment on lines -279 to +283

      Nah by OR I meant either or... let's make a choice. Let's go for \Stringable. MarkupInterface enforces that you implement __toString() which is the same as the pseudo-interface \Stringable so \Drupal\Component\Render\MarkupInterface|\Stringable is kinda pointless. How I guess if someone has overridden this method and has a return typehint on TranslatableMarkup then this will still work because it would be a narrowing of return types so let's still with this.

    • Please register or sign in to reply
    Please register or sign in to reply
    Loading