Skip to content
Snippets Groups Projects

Issue #3483196: Tokens are HTML encoded

1 file
+ 12
2
Compare changes
  • Side-by-side
  • Inline
@@ -45,11 +45,18 @@ abstract class TokenSettingTypeBase extends PatternSettingTypeBase implements Co
'#type' => 'textfield',
'#title' => $def->getLabel(),
'#description' => $description,
'#default_value' => $this->getValue($value),
'#default_value' => $this->getValue($value)['input'],
'#attributes' => ['class' => ['js-ui-patterns-settings-show-token-link']],
];
$this->handleInput($form[$def->getName()]['input'], $def, $form_type);
$form[$def->getName()]['render_as_html'] = [
'#type' => 'checkbox',
'#title' => $this->t('Rendered as HTML'),
'#description' => $this->t('When rendering tokens as HTML, some characters will be encoded.'),
'#default_value' => $this->getValue($value)['render_as_html'] ?? TRUE,
];
return $form;
}
@@ -59,6 +66,8 @@ abstract class TokenSettingTypeBase extends PatternSettingTypeBase implements Co
public function settingsPreprocess($value, array $context, PatternDefinitionSetting $def) {
$return_value = '';
$render_as_html = !empty($value['render_as_html']);
if (is_array($value) && isset($value['input'])) {
$value = $value['input'];
}
@@ -71,7 +80,8 @@ abstract class TokenSettingTypeBase extends PatternSettingTypeBase implements Co
$token_data[$entity->getEntityTypeId()] = $entity;
}
try {
$return_value = $this->getTokenService()->replace($value, $token_data, ['clear' => TRUE]);
$method = $render_as_html ? 'replace' : 'replacePlain';
$return_value = $this->getTokenService()->{$method}($value, $token_data, ['clear' => TRUE]);
}
catch (EntityMalformedException $e) {
if (!ui_patterns_settings_is_layout_builder_route()) {
Loading