Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 292435

SDC ComponentElement: Transform slots TranslatableMarkup values to #markup instead of throwing an exception

$
0
0

Problem/Motivation

This can be seen as a follow-up for #3391702

On that issue, it was proposed that #slots were made more resilient and forgiving by accepting non-scalar values.

Another common Drupalism we might be facing on slots are translated strings, which

  1. Can include simple inline HTML tags, like <br> or <em>
  2. Will take the shape of a TranslatableMarkup, which will fail both the is_scalar and Element::isRenderArray checks and, as such, will be rejected witj an exception

Steps to reproduce

Try to feed a translated string (with or without HTML) to a slot:

      return [
        '#type' => 'component',
        '#component' => 'theme:icon_message',
        '#props' => [
          'icon' => $this->options['icon'],
        ],
        '#slots' => [
          'message' => $this->t('No @type were found.<br> Please try again later.', ['@type' => $this->options['content_type']]),
        ]
      ];

A 'Unable to render component "%s". A render array or a scalar is expected for the slot "%s" when using the render element with the "#slots" property', will be thrown.

Proposed resolution

As we did with scalars, wrap the translatable markup in order to make it pass the checks and render.

Remaining tasks

Propose a MR

User interface changes

None

Introduced terminology

None

API changes

None

Data model changes

None

Release notes snippet


Viewing all articles
Browse latest Browse all 292435

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>