Commit e5809400 authored by catch's avatar catch

Issue #2559605 by Cottser, stefan.r: Convert SafeMarkup::checkPlain() in...

Issue #2559605 by Cottser, stefan.r: Convert SafeMarkup::checkPlain() in render arrays to #plain_text
parent b833f73b
......@@ -8,7 +8,6 @@
namespace Drupal\Core\Block;
use Drupal\block\BlockInterface;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Cache\CacheableDependencyInterface;
use Drupal\Core\Form\FormStateInterface;
......@@ -166,7 +165,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
$form['admin_label'] = array(
'#type' => 'item',
'#title' => $this->t('Block description'),
'#markup' => SafeMarkup::checkPlain($definition['admin_label']),
'#plain_text' => $definition['admin_label'],
);
$form['label'] = array(
'#type' => 'textfield',
......
......@@ -8,7 +8,6 @@
namespace Drupal\Core\Field\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Component\Utility\SafeMarkup;
/**
* Plugin implementation of the 'entity reference ID' formatter.
......@@ -33,7 +32,7 @@ public function viewElements(FieldItemListInterface $items) {
foreach ($this->getEntitiesToView($items) as $delta => $entity) {
if ($entity->id()) {
$elements[$delta] = array(
'#markup' => SafeMarkup::checkPlain($entity->id()),
'#plain_text' => $entity->id(),
// Create a cache tag entry for the referenced entity. In the case
// that the referenced entity is deleted, the cache for referring
// entities must be cleared.
......
......@@ -7,7 +7,6 @@
namespace Drupal\Core\Field\Plugin\Field\FieldFormatter;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Core\Entity\Exception\UndefinedLinkTemplateException;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Form\FormStateInterface;
......@@ -98,7 +97,7 @@ public function viewElements(FieldItemListInterface $items) {
}
}
else {
$elements[$delta] = array('#markup' => SafeMarkup::checkPlain($label));
$elements[$delta] = array('#plain_text' => $label);
}
$elements[$delta]['#cache']['tags'] = $entity->getCacheTags();
}
......
......@@ -9,7 +9,6 @@
use Drupal\Component\Utility\Html;
use Drupal\Component\Serialization\Json;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityStorageInterface;
......@@ -261,7 +260,7 @@ protected function buildBlocksForm() {
$form[$entity_id]['#attributes']['class'][] = 'js-block-placed';
}
$form[$entity_id]['info'] = array(
'#markup' => SafeMarkup::checkPlain($info['label']),
'#plain_text' => $info['label'],
'#wrapper_attributes' => array(
'class' => array('block'),
),
......
......@@ -8,7 +8,6 @@
namespace Drupal\block\Tests;
use Drupal\Core\Cache\Cache;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Core\Form\FormState;
use Drupal\simpletest\KernelTestBase;
use Drupal\block\BlockInterface;
......@@ -73,7 +72,7 @@ public function testBlockInterface() {
'admin_label' => array(
'#type' => 'item',
'#title' => t('Block description'),
'#markup' => SafeMarkup::checkPlain($definition['admin_label']),
'#plain_text' => $definition['admin_label'],
),
'label' => array(
'#type' => 'textfield',
......
......@@ -9,7 +9,6 @@
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityViewBuilder;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Core\Mail\MailFormatHelper;
use Drupal\Core\Render\Element;
......@@ -42,7 +41,7 @@ public function buildComponents(array &$build, array $entities, array $displays,
$build[$id]['message'] = array(
'#type' => 'item',
'#title' => t('Message'),
'#markup' => SafeMarkup::checkPlain($entity->getMessage()),
'#plain_text' => $entity->getMessage(),
);
}
}
......
......@@ -5,7 +5,6 @@
* The content translation administration forms.
*/
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Core\Config\Entity\ThirdPartySettingsInterface;
use Drupal\Core\Entity\ContentEntityTypeInterface;
use Drupal\Core\Entity\EntityTypeInterface;
......@@ -216,10 +215,10 @@ function _content_translation_preprocess_language_content_settings_table(&$varia
'bundle' => array(
'#prefix' => '<span class="visually-hidden">',
'#suffix' => '</span> ',
'#markup' => SafeMarkup::checkPlain($element[$bundle]['settings']['#label']),
'#plain_text' => $element[$bundle]['settings']['#label'],
),
'field' => array(
'#markup' => SafeMarkup::checkPlain($field_element['#label']),
'#plain_text' => $field_element['#label'],
),
),
'class' => array('field'),
......@@ -250,15 +249,15 @@ function _content_translation_preprocess_language_content_settings_table(&$varia
'bundle' => array(
'#prefix' => '<span class="visually-hidden">',
'#suffix' => '</span> ',
'#markup' => SafeMarkup::checkPlain($element[$bundle]['settings']['#label']),
'#plain_text' => $element[$bundle]['settings']['#label'],
),
'field' => array(
'#prefix' => '<span class="visually-hidden">',
'#suffix' => '</span> ',
'#markup' => SafeMarkup::checkPlain($field_element['#label']),
'#plain_text' => $field_element['#label'],
),
'columns' => array(
'#markup' => SafeMarkup::checkPlain($column_label),
'#plain_text' => $column_label,
),
),
'class' => array('column'),
......
......@@ -174,7 +174,7 @@ public function testIdFormatter() {
$formatter = 'entity_reference_entity_id';
$build = $this->buildRenderArray([$this->referencedEntity, $this->unsavedReferencedEntity], $formatter);
$this->assertEqual($build[0]['#markup'], $this->referencedEntity->id(), sprintf('The markup returned by the %s formatter is correct for an item with a saved entity.', $formatter));
$this->assertEqual($build[0]['#plain_text'], $this->referencedEntity->id(), sprintf('The markup returned by the %s formatter is correct for an item with a saved entity.', $formatter));
$this->assertEqual($build[0]['#cache']['tags'], $this->referencedEntity->getCacheTags(), sprintf('The %s formatter has the expected cache tags.', $formatter));
$this->assertTrue(!isset($build[1]), sprintf('The markup returned by the %s formatter is correct for an item with a unsaved entity.', $formatter));
}
......@@ -244,7 +244,7 @@ public function testLabelFormatter() {
// The second referenced entity is "autocreated", therefore not saved and
// lacking any URL info.
$expected_item_2 = array(
'#markup' => $this->unsavedReferencedEntity->label(),
'#plain_text' => $this->unsavedReferencedEntity->label(),
'#cache' => array(
'contexts' => [
'user.permissions',
......@@ -257,8 +257,8 @@ public function testLabelFormatter() {
// Test with the 'link' setting set to FALSE.
$build = $this->buildRenderArray([$this->referencedEntity, $this->unsavedReferencedEntity], $formatter, array('link' => FALSE));
$this->assertEqual($build[0]['#markup'], $this->referencedEntity->label(), sprintf('The markup returned by the %s formatter is correct for an item with a saved entity.', $formatter));
$this->assertEqual($build[1]['#markup'], $this->unsavedReferencedEntity->label(), sprintf('The markup returned by the %s formatter is correct for an item with a unsaved entity.', $formatter));
$this->assertEqual($build[0]['#plain_text'], $this->referencedEntity->label(), sprintf('The markup returned by the %s formatter is correct for an item with a saved entity.', $formatter));
$this->assertEqual($build[1]['#plain_text'], $this->unsavedReferencedEntity->label(), sprintf('The markup returned by the %s formatter is correct for an item with a unsaved entity.', $formatter));
// Test an entity type that doesn't have any link templates, which means
// \Drupal\Core\Entity\EntityInterface::urlInfo() will throw an exception
......@@ -273,7 +273,7 @@ public function testLabelFormatter() {
$referenced_entity_with_no_link_template->save();
$build = $this->buildRenderArray([$referenced_entity_with_no_link_template], $formatter, array('link' => TRUE));
$this->assertEqual($build[0]['#markup'], $referenced_entity_with_no_link_template->label(), sprintf('The markup returned by the %s formatter is correct for an entity type with no valid link template.', $formatter));
$this->assertEqual($build[0]['#plain_text'], $referenced_entity_with_no_link_template->label(), sprintf('The markup returned by the %s formatter is correct for an entity type with no valid link template.', $formatter));
}
/**
......
......@@ -10,7 +10,6 @@
use Drupal\Component\Plugin\Factory\DefaultFactory;
use Drupal\Component\Plugin\PluginManagerBase;
use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Core\Entity\EntityForm;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityWithPluginCollectionInterface;
......@@ -290,7 +289,7 @@ protected function buildFieldRow(FieldDefinitionInterface $field_definition, arr
'defaultPlugin' => $this->getDefaultPlugin($field_definition->getType()),
),
'human_name' => array(
'#markup' => SafeMarkup::checkPlain($label),
'#plain_text' => $label,
),
'weight' => array(
'#type' => 'textfield',
......
......@@ -12,7 +12,6 @@
use Drupal\Core\Url;
use Drupal\image\ConfigurableImageEffectInterface;
use Drupal\image\ImageEffectManager;
use Drupal\Component\Utility\SafeMarkup;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
......@@ -99,7 +98,7 @@ public function form(array $form, FormStateInterface $form_state) {
'#tree' => FALSE,
'data' => array(
'label' => array(
'#markup' => SafeMarkup::checkPlain($effect->label()),
'#plain_text' => $effect->label(),
),
),
);
......
......@@ -5,7 +5,6 @@
* Administration functions for language.module.
*/
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Core\Render\Element;
use Drupal\Core\Template\Attribute;
use Drupal\Core\Url;
......@@ -170,7 +169,7 @@ function template_preprocess_language_content_settings_table(&$variables) {
'data' => array(
'#prefix' => '<label>',
'#suffix' => '</label>',
'#markup' => SafeMarkup::checkPlain($element[$bundle]['settings']['#label']),
'#plain_text' => $element[$bundle]['settings']['#label'],
),
'class' => array('bundle'),
),
......
......@@ -7,7 +7,6 @@
namespace Drupal\link\Plugin\Field\FieldFormatter;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Component\Utility\Unicode;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Field\FieldDefinitionInterface;
......@@ -201,7 +200,7 @@ public function viewElements(FieldItemListInterface $items) {
if (!empty($settings['url_only']) && !empty($settings['url_plain'])) {
$element[$delta] = array(
'#markup' => SafeMarkup::checkPlain($link_title),
'#plain_text' => $link_title,
);
if (!empty($item->_attributes)) {
......
......@@ -7,7 +7,6 @@
namespace Drupal\rest\Plugin\views\display;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Cache\CacheableResponse;
use Drupal\Core\Render\RenderContext;
......@@ -318,11 +317,12 @@ public function render() {
$this->view->element['#content_type'] = $this->getMimeType();
$this->view->element['#cache_properties'][] = '#content_type';
// Wrap the output in a pre tag if this is for a live preview.
// Encode and wrap the output in a pre tag if this is for a live preview.
if (!empty($this->view->live_preview)) {
$build['#prefix'] = '<pre>';
$build['#markup'] = SafeMarkup::checkPlain($build['#markup']);
$build['#plain_text'] = $build['#markup'];
$build['#suffix'] = '</pre>';
unset($build['#markup']);
}
elseif ($this->view->getRequest()->getFormat($this->view->element['#content_type']) !== 'html') {
// This display plugin is primarily for returning non-HTML formats.
......
......@@ -480,16 +480,16 @@ public function testLivePreview() {
$entities[] = $row->_entity;
}
$expected = Html::escape($serializer->serialize($entities, 'json'));
$expected = $serializer->serialize($entities, 'json');
$view->live_preview = TRUE;
$build = $view->preview();
$rendered_json = $build['#markup'];
$this->assertEqual($rendered_json, $expected, 'Ensure the previewed json is escaped.');
$rendered_json = $build['#plain_text'];
$this->assertTrue(!isset($build['#markup']) && $rendered_json == $expected, 'Ensure the previewed json is escaped.');
$view->destroy();
$expected = Html::escape($serializer->serialize($entities, 'xml'));
$expected = $serializer->serialize($entities, 'xml');
// Change the request format to xml.
$view->setDisplay('rest_export_1');
......@@ -505,7 +505,7 @@ public function testLivePreview() {
$this->executeView($view);
$build = $view->preview();
$rendered_xml = $build['#markup'];
$rendered_xml = $build['#plain_text'];
$this->assertEqual($rendered_xml, $expected, 'Ensure we preview xml when we change the request format.');
}
......
......@@ -8,7 +8,6 @@
namespace Drupal\simpletest\Form;
use Drupal\Component\Utility\SortArray;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\RendererInterface;
......@@ -179,7 +178,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
);
$form['tests'][$class]['description'] = array(
'#prefix' => '<div class="description">',
'#markup' => SafeMarkup::checkPlain($info['description']),
'#plain_text' => $info['description'],
'#suffix' => '</div>',
'#wrapper_attributes' => array(
'class' => array('simpletest-test-description', 'table-filter-text-source'),
......
......@@ -7,7 +7,6 @@
namespace Drupal\entity_test;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityViewBuilder;
......@@ -36,7 +35,7 @@ public function buildComponents(array &$build, array $entities, array $displays,
foreach ($entities as $id => $entity) {
$build[$id]['label'] = array(
'#weight' => -100,
'#markup' => SafeMarkup::checkPlain($entity->label()),
'#plain_text' => $entity->label(),
);
$build[$id]['separator'] = array(
'#weight' => -150,
......@@ -44,7 +43,7 @@ public function buildComponents(array &$build, array $entities, array $displays,
);
$build[$id]['view_mode'] = array(
'#weight' => -200,
'#markup' => SafeMarkup::checkPlain($view_mode),
'#plain_text' => $view_mode,
);
}
}
......
......@@ -7,7 +7,6 @@
namespace Drupal\entity_test;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Core\Entity\EntityInterface;
/**
......@@ -20,7 +19,7 @@ class EntityTestViewBuilderOverriddenView extends EntityTestViewBuilder {
*/
public function view(EntityInterface $entity, $view_mode = 'full', $langcode = NULL) {
$build = [];
$build[$entity->id()]['#markup'] = SafeMarkup::checkPlain($entity->label());
$build[$entity->id()]['#plain_text'] = $entity->label();
return $build;
}
......
......@@ -7,7 +7,6 @@
namespace Drupal\form_test\Form;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
......@@ -57,7 +56,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
*/
function form_test_storage_page_cache_old_build_id($form) {
if (isset($form['#build_id_old'])) {
$form['test_build_id_old']['#markup'] = SafeMarkup::checkPlain($form['#build_id_old']);
$form['test_build_id_old']['#plain_text'] = $form['#build_id_old'];
}
return $form;
}
......
......@@ -99,7 +99,7 @@ public function preview() {
if (!empty($this->view->live_preview)) {
$output = array(
'#prefix' => '<pre>',
'#markup' => SafeMarkup::checkPlain(drupal_render_root($output)),
'#plain_text' => drupal_render_root($output),
'#suffix' => '</pre>',
);
}
......
......@@ -7,7 +7,6 @@
namespace Drupal\views_ui\Controller;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Url;
use Drupal\views\ViewExecutable;
......@@ -89,7 +88,7 @@ public function reportFields() {
$header = array(t('Field name'), t('Used in'));
$rows = array();
foreach ($fields as $field_name => $views) {
$rows[$field_name]['data'][0] = SafeMarkup::checkPlain($field_name);
$rows[$field_name]['data'][0]['data']['#plain_text'] = $field_name;
foreach ($views as $view) {
$rows[$field_name]['data'][1][] = $this->l($view, new Url('entity.view.edit_form', array('view' => $view)));
}
......
......@@ -102,7 +102,7 @@ public function buildRow(EntityInterface $view) {
),
'description' => array(
'data' => array(
'#markup' => SafeMarkup::checkPlain($view->get('description')),
'#plain_text' => $view->get('description'),
),
'class' => array('views-table-filter-text-source'),
),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment