Since a short time descriptions in GA module are checkplained.
This is correct code:
$site_search_dependencies = '<div class="admin-requirements">';
$site_search_dependencies .= t('Requires: !module-list', array('!module-list' => (\Drupal::moduleHandler()->moduleExists('search') ? t('@module (<span class="admin-enabled">enabled</span>)', array('@module' => 'Search')) : t('@module (<span class="admin-disabled">disabled</span>)', array('@module' => 'Search')))));
$site_search_dependencies .= '</div>';
$form['tracking']['search_and_advertising']['google_analytics_site_search'] = array(
'#type' => 'checkbox',
'#title' => t('Track internal search'),
'#description' => t('If checked, internal search keywords are tracked. You must configure your Google account to use the internal query parameter <strong>search</strong>. For more information see <a href="@url">Setting Up Site Search for a Profile</a>.', array('@url' => 'https://support.google.com/analytics/answer/1012264')) . $site_search_dependencies,
'#default_value' => $config->get('track.site_search'),
'#disabled' => (\Drupal::moduleHandler()->moduleExists('search') ? FALSE : TRUE),
);
Why does this happen and how should this fixed?
Comments
Comment #1
fabianx commentedThis does happen, because you concat a safe string - coming from t() with an unsafe one.
In this particular case I think you know that the string is safe, so you can do:
Comment #2
hass commentedNope. This is against translation string rules. That is technically possible, but forbidden.
Comment #3
xjmI believe the correct solution is to either use templates or #2289999: Add an easy way to create HTML on the fly without having to create a theme function / template?
Comment #4
hass commentedI'm asking me how I could implement a template inside a
#descriptionform field... that is not documented.Comment #5
hass commentedAlso tried
SafeMarkup::set($site_search_dependencies)in the form, but this is not working. Also tried setting it on the strings, but it can only be wrong to set this on a t()'ified string. not working here too. I still see<span class="admin-enabled">enabled</span>in config pages.Comment #6
mpdonadioYou can use an inline template in the #description
Normal usage for Twig applies.
Comment #7
fabianx commentedWe are working on a generic fix in core.
I am sorry to leave you waiting, but this should be working soon:
#2324371: Fix common HTML escaped render #key values due to Twig autoescape
Comment #8
hass commented@Fabianx: Thanks for the link. Marking fixed.