Commit 42c9be93 authored by catch's avatar catch

Issue #2560851 by alexpott, Xano: Deprecate EntityListBuilder::getLabel() and...

Issue #2560851 by alexpott, Xano: Deprecate EntityListBuilder::getLabel() and remove usages of SafeMarkup::checkPlain()
parent 3f31dbed
......@@ -9,7 +9,6 @@
use Drupal\Core\Extension\ModuleHandlerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Component\Utility\SafeMarkup;
/**
* Defines a generic implementation to build a listing of entities.
......@@ -106,16 +105,20 @@ protected function getEntityIds() {
}
/**
* Gets the escaped label of an entity.
* Gets the label of an entity.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity being listed.
*
* @return string
* The escaped entity label.
* The entity label.
*
* @deprecated in Drupal 8.0.x, will be removed before Drupal 9.0.0
* Use $entity->label() instead. This method used to escape the entity
* label. The render system's autoescape is now relied upon.
*/
protected function getLabel(EntityInterface $entity) {
return SafeMarkup::checkPlain($entity->label());
return $entity->label();
}
/**
......
......@@ -80,7 +80,7 @@ public function load() {
*/
public function buildRow(EntityInterface $entity) {
$row['type'] = $entity->getType();
$row['label'] = $this->getLabel($entity);
$row['label'] = $entity->label();
if ($this->hasConfigurableActions) {
$row += parent::buildRow($entity);
}
......
......@@ -29,7 +29,7 @@ public function buildHeader() {
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity) {
$row['label'] = $this->getLabel($entity);
$row['label'] = $entity->label();
return $row + parent::buildRow($entity);
}
......
......@@ -30,7 +30,7 @@ public function buildHeader() {
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity) {
$row['label'] = $this->getLabel($entity);
$row['label'] = $entity->label();
$row['id'] = $entity->id();
return $row + parent::buildRow($entity);
}
......
......@@ -65,7 +65,7 @@ public function buildRow(EntityInterface $entity) {
$plugin_definition = $entity->getPlugin()->getPluginDefinition();
$row['label'] = array(
'data' => $this->getLabel($entity),
'data' => $entity->label(),
'class' => 'table-filter-text-source',
);
......
......@@ -68,7 +68,7 @@ public function render() {
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity) {
$row['label']['data'] = $this->getLabel($entity);
$row['label']['data'] = $entity->label();
$row['label']['class'][] = 'table-filter-text-source';
return $row + parent::buildRow($entity);
}
......
......@@ -116,7 +116,7 @@ public function getFilterLabels() {
*/
public function buildRow(EntityInterface $entity) {
$row['label'] = array(
'data' => $this->getLabel($entity),
'data' => $entity->label(),
'class' => 'table-filter-text-source',
);
......
......@@ -35,7 +35,7 @@ public function buildHeader() {
public function buildRow(EntityInterface $entity) {
// Special case the personal form.
if ($entity->id() == 'personal') {
$row['form'] = $this->getLabel($entity);
$row['form'] = $entity->label();
$row['recipients'] = t('Selected user');
$row['selected'] = t('No');
}
......
......@@ -68,7 +68,7 @@ public function buildHeader() {
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity) {
$row['label'] = $this->getLabel($entity);
$row['label'] = $entity->label();
return $row + parent::buildRow($entity);
}
......
......@@ -93,7 +93,7 @@ public function buildHeader() {
public function buildRow(EntityInterface $entity) {
// Check whether this is the fallback text format. This format is available
// to all roles and cannot be disabled via the admin interface.
$row['label'] = $this->getLabel($entity);
$row['label'] = $entity->label();
$row['roles'] = [];
if ($entity->isFallbackFormat()) {
$fallback_choice = $this->configFactory->get('filter.settings')->get('always_show_fallback_choice');
......
......@@ -67,7 +67,7 @@ public function buildHeader() {
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity) {
$row['label'] = $this->getLabel($entity);
$row['label'] = $entity->label();
return $row + parent::buildRow($entity);
}
......
......@@ -107,7 +107,7 @@ public function buildHeader() {
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity) {
$row['label'] = $this->getLabel($entity);
$row['label'] = $entity->label();
$row['default'] = array(
'#type' => 'radio',
'#parents' => array('site_default_language'),
......
......@@ -36,7 +36,7 @@ public function buildHeader() {
*/
public function buildRow(EntityInterface $entity) {
$row['title'] = array(
'data' => $this->getLabel($entity),
'data' => $entity->label(),
'class' => array('menu-label'),
);
$row['description']['data'] = ['#markup' => $entity->getDescription()];
......
......@@ -35,7 +35,7 @@ public function buildHeader() {
*/
public function buildRow(EntityInterface $entity) {
$row['title'] = array(
'data' => $this->getLabel($entity),
'data' => $entity->label(),
'class' => array('menu-label'),
);
$row['description']['data'] = ['#markup' => $entity->getDescription()];
......
......@@ -28,7 +28,7 @@ public function buildHeader() {
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity) {
$row['label'] = $this->getLabel($entity);
$row['label'] = $entity->label();
$row['id'] = $entity->id();
return $row + parent::buildRow($entity);
}
......
......@@ -121,7 +121,7 @@ public function buildHeader() {
*/
public function buildRow(EntityInterface $entity) {
/** @var $entity \Drupal\search\SearchPageInterface */
$row['label'] = $this->getLabel($entity);
$row['label'] = $entity->label();
$row['url']['#markup'] = 'search/' . $entity->getPath();
// If the search page is active, link to it.
if ($entity->status()) {
......
......@@ -7,7 +7,6 @@
namespace Drupal\shortcut\Form;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Routing\RouteMatchInterface;
......@@ -71,7 +70,7 @@ public function buildForm(array $form, FormStateInterface $form_state, UserInter
// Prepare the list of shortcut sets.
$options = array_map(function (ShortcutSet $set) {
return SafeMarkup::checkPlain($set->label());
return $set->label();
}, $this->shortcutSetStorage->loadMultiple());
$current_set = shortcut_current_displayed_set($this->user);
......
......@@ -46,7 +46,7 @@ public function getDefaultOperations(EntityInterface $entity) {
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity) {
$row['name'] = $this->getLabel($entity);
$row['name'] = $entity->label();
return $row + parent::buildRow($entity);
}
......
......@@ -68,7 +68,7 @@ public function buildHeader() {
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity) {
$row['label'] = $this->getLabel($entity);
$row['label'] = $entity->label();
$row['pattern'] = $this->dateFormatter->format(REQUEST_TIME, $entity->id());
return $row + parent::buildRow($entity);
}
......
......@@ -30,7 +30,7 @@ public function buildHeader() {
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity) {
$row['label'] = $this->getLabel($entity);
$row['label'] = $entity->label();
$row['id'] = $entity->id();
return $row + parent::buildRow($entity);
}
......
......@@ -68,7 +68,7 @@ public function buildHeader() {
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity) {
$row['label'] = $this->getLabel($entity);
$row['label'] = $entity->label();
return $row + parent::buildRow($entity);
}
......
......@@ -37,7 +37,7 @@ public function buildHeader() {
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity) {
$row['label'] = $this->getLabel($entity);
$row['label'] = $entity->label();
return $row + parent::buildRow($entity);
}
......
......@@ -137,64 +137,6 @@ public function testGetOperations() {
$this->assertArrayHasKey('title', $operations[$operation_name]);
}
/**
* Tests that buildRow() returns a string which has been run through
* SafeMarkup::checkPlain().
*
* @dataProvider providerTestBuildRow
*
* @param string $input
* The entity label being passed into buildRow.
* @param string $expected
* The expected output of the label from buildRow.
* @param string $message
* The message to provide as output for the test.
* @param bool $ignorewarnings
* Whether or not to ignore PHP 5.3+ invalid multibyte sequence warnings.
*
* @see \Drupal\Core\Entity\EntityListBuilder::buildRow()
*/
public function testBuildRow($input, $expected, $message, $ignorewarnings = FALSE) {
$this->role->expects($this->any())
->method('label')
->will($this->returnValue($input));
if ($ignorewarnings) {
$built_row = @$this->entityListBuilder->buildRow($this->role);
}
else {
$built_row = $this->entityListBuilder->buildRow($this->role);
}
$this->assertEquals($built_row['label'], $expected, $message);
}
/**
* Data provider for testBuildRow().
*
* @see self::testBuildRow()
* @see \Drupal\Tests\Component\Utility\SafeMarkupTest::providerCheckPlain()
*
* @return array
* An array containing a string, the expected return from
* SafeMarkup::checkPlain, a message to be output for failures, and whether the
* test should be processed as multibyte.
*/
public function providerTestBuildRow() {
$tests = array();
// Checks that invalid multi-byte sequences are escaped.
$tests[] = array("Foo\xC0barbaz", 'Foo�barbaz', 'EntityTestListBuilder::buildRow() escapes invalid sequence "Foo\xC0barbaz"', TRUE);
$tests[] = array("\xc2\"", '�"', 'EntityTestListBuilder::buildRow escapes invalid sequence "\xc2\""', TRUE);
$tests[] = array("Fooÿñ", "Fooÿñ", 'EntityTestListBuilder::buildR does not escape valid sequence "Fooÿñ"');
// Checks that special characters are escaped.
$tests[] = array("<script>", '&lt;script&gt;', 'EntityTestListBuilder::buildRow() escapes &lt;script&gt;');
$tests[] = array('<>&"\'', '&lt;&gt;&amp;&quot;&#039;', 'EntityTestListBuilder::buildRow() escapes reserved HTML characters.');
return $tests;
}
}
class TestEntityListBuilder extends EntityTestListBuilder {
......
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