Commit d663924e authored by alexpott's avatar alexpott

Issue #2064557 by tim.plunkett: Improve strange coupling in...

Issue #2064557 by tim.plunkett: Improve strange coupling in EntityListControllers by improving buildRow() and buildHeader().
parent 5b001b81
...@@ -91,6 +91,19 @@ public function load() { ...@@ -91,6 +91,19 @@ public function load() {
return $this->storage->loadMultiple(); return $this->storage->loadMultiple();
} }
/**
* Returns the escaped label of an entity.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity being listed.
*
* @return string
* The escaped entity label.
*/
protected function getLabel(EntityInterface $entity) {
return String::checkPlain($entity->label());
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
...@@ -127,8 +140,6 @@ public function getOperations(EntityInterface $entity) { ...@@ -127,8 +140,6 @@ public function getOperations(EntityInterface $entity) {
* @see Drupal\Core\Entity\EntityListController::render() * @see Drupal\Core\Entity\EntityListController::render()
*/ */
public function buildHeader() { public function buildHeader() {
$row['label'] = t('Label');
$row['id'] = t('Machine name');
$row['operations'] = t('Operations'); $row['operations'] = t('Operations');
return $row; return $row;
} }
...@@ -145,10 +156,7 @@ public function buildHeader() { ...@@ -145,10 +156,7 @@ public function buildHeader() {
* @see Drupal\Core\Entity\EntityListController::render() * @see Drupal\Core\Entity\EntityListController::render()
*/ */
public function buildRow(EntityInterface $entity) { public function buildRow(EntityInterface $entity) {
$row['label'] = String::checkPlain($entity->label()); $row['operations']['data'] = $this->buildOperations($entity);
$row['id'] = $entity->id();
$operations = $this->buildOperations($entity);
$row['operations']['data'] = $operations;
return $row; return $row;
} }
......
...@@ -86,9 +86,9 @@ public function load() { ...@@ -86,9 +86,9 @@ public function load() {
*/ */
public function buildRow(EntityInterface $entity) { public function buildRow(EntityInterface $entity) {
$row['type'] = $entity->getType(); $row['type'] = $entity->getType();
$row['label'] = String::checkPlain($entity->label()); $row['label'] = $this->getLabel($entity);
if ($this->hasConfigurableActions) { if ($this->hasConfigurableActions) {
$row['operations']['data'] = $this->buildOperations($entity); $row += parent::buildRow($entity);
} }
return $row; return $row;
} }
...@@ -100,8 +100,7 @@ public function buildHeader() { ...@@ -100,8 +100,7 @@ public function buildHeader() {
$header = array( $header = array(
'type' => t('Action type'), 'type' => t('Action type'),
'label' => t('Label'), 'label' => t('Label'),
'operations' => t('Operations'), ) + parent::buildHeader();
);
return $header; return $header;
} }
......
...@@ -19,19 +19,16 @@ class CustomBlockListController extends EntityListController { ...@@ -19,19 +19,16 @@ class CustomBlockListController extends EntityListController {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function buildHeader() { public function buildHeader() {
$header = parent::buildHeader();
$header['label'] = t('Block description'); $header['label'] = t('Block description');
unset($header['id']); return $header + parent::buildHeader();
return $header;
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function buildRow(EntityInterface $entity) { public function buildRow(EntityInterface $entity) {
$row = parent::buildRow($entity); $row['label'] = $this->getLabel($entity);
unset($row['id']); return $row + parent::buildRow($entity);
return $row;
} }
/** /**
......
...@@ -48,22 +48,19 @@ public function getOperations(EntityInterface $entity) { ...@@ -48,22 +48,19 @@ public function getOperations(EntityInterface $entity) {
* Overrides \Drupal\Core\Entity\EntityListController::buildHeader(). * Overrides \Drupal\Core\Entity\EntityListController::buildHeader().
*/ */
public function buildHeader() { public function buildHeader() {
$row['type'] = t('Block type'); $header['type'] = t('Block type');
$row['description'] = t('Description'); $header['description'] = t('Description');
$row['operations'] = t('Operations'); return $header + parent::buildHeader();
return $row;
} }
/** /**
* Overrides \Drupal\Core\Entity\EntityListController::buildRow(). * Overrides \Drupal\Core\Entity\EntityListController::buildRow().
*/ */
public function buildRow(EntityInterface $entity) { public function buildRow(EntityInterface $entity) {
parent::buildRow($entity);
$uri = $entity->uri(); $uri = $entity->uri();
$row['type'] = l($entity->label(), $uri['path'], $uri['options']); $row['type'] = l($entity->label(), $uri['path'], $uri['options']);
$row['description'] = filter_xss_admin($entity->description); $row['description'] = filter_xss_admin($entity->description);
$row['operations']['data'] = $this->buildOperations($entity); return $row + parent::buildRow($entity);
return $row;
} }
/** /**
......
<?php
/**
* @file
* Contains \Drupal\config_test\ConfigTestListController.
*/
namespace Drupal\config_test;
use Drupal\Core\Config\Entity\ConfigEntityListController;
use Drupal\Core\Entity\EntityInterface;
/**
* Provides a list controller for config_test.
*/
class ConfigTestListController extends ConfigEntityListController {
/**
* {@inheritdoc}
*/
public function buildHeader() {
$header['label'] = t('Label');
$header['id'] = t('Machine name');
return $header + parent::buildHeader();
}
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity) {
$row['label'] = $this->getLabel($entity);
$row['id'] = $entity->id();
return $row + parent::buildRow($entity);
}
}
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
* module = "config_test", * module = "config_test",
* controllers = { * controllers = {
* "storage" = "Drupal\config_test\ConfigTestStorageController", * "storage" = "Drupal\config_test\ConfigTestStorageController",
* "list" = "Drupal\Core\Config\Entity\ConfigEntityListController", * "list" = "Drupal\config_test\ConfigTestListController",
* "form" = { * "form" = {
* "default" = "Drupal\config_test\ConfigTestFormController", * "default" = "Drupal\config_test\ConfigTestFormController",
* "delete" = "Drupal\config_test\Form\ConfigTestDeleteForm" * "delete" = "Drupal\config_test\Form\ConfigTestDeleteForm"
......
...@@ -47,18 +47,17 @@ public function getOperations(EntityInterface $entity) { ...@@ -47,18 +47,17 @@ public function getOperations(EntityInterface $entity) {
* Overrides Drupal\Core\Entity\EntityListController::buildHeader(). * Overrides Drupal\Core\Entity\EntityListController::buildHeader().
*/ */
public function buildHeader() { public function buildHeader() {
$row['category'] = t('Category'); $header['category'] = t('Category');
$row['recipients'] = t('Recipients'); $header['recipients'] = t('Recipients');
$row['selected'] = t('Selected'); $header['selected'] = t('Selected');
$row['operations'] = t('Operations'); return $header + parent::buildHeader();
return $row;
} }
/** /**
* Overrides Drupal\Core\Entity\EntityListController::buildRow(). * Overrides Drupal\Core\Entity\EntityListController::buildRow().
*/ */
public function buildRow(EntityInterface $entity) { public function buildRow(EntityInterface $entity) {
$row['category'] = check_plain($entity->label()); $row['category'] = $this->getLabel($entity);
// Special case the personal category. // Special case the personal category.
if ($entity->id() == 'personal') { if ($entity->id() == 'personal') {
$row['recipients'] = t('Selected user'); $row['recipients'] = t('Selected user');
...@@ -69,8 +68,7 @@ public function buildRow(EntityInterface $entity) { ...@@ -69,8 +68,7 @@ public function buildRow(EntityInterface $entity) {
$default_category = \Drupal::config('contact.settings')->get('default_category'); $default_category = \Drupal::config('contact.settings')->get('default_category');
$row['selected'] = ($default_category == $entity->id() ? t('Yes') : t('No')); $row['selected'] = ($default_category == $entity->id() ? t('Yes') : t('No'));
} }
$row['operations']['data'] = $this->buildOperations($entity); return $row + parent::buildRow($entity);
return $row;
} }
} }
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
namespace Drupal\entity; namespace Drupal\entity;
use Drupal\Component\Utility\String;
use Drupal\Core\Config\Entity\ConfigEntityListController; use Drupal\Core\Config\Entity\ConfigEntityListController;
use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityStorageControllerInterface; use Drupal\Core\Entity\EntityStorageControllerInterface;
...@@ -64,18 +63,16 @@ public static function createInstance(ContainerInterface $container, $entity_typ ...@@ -64,18 +63,16 @@ public static function createInstance(ContainerInterface $container, $entity_typ
* {@inheritdoc} * {@inheritdoc}
*/ */
public function buildHeader() { public function buildHeader() {
$header = parent::buildHeader(); $header['label'] = t('Label');
unset($header['id']); return $header + parent::buildHeader();
return $header;
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function buildRow(EntityInterface $entity) { public function buildRow(EntityInterface $entity) {
$row = parent::buildRow($entity); $row['label'] = $this->getLabel($entity);
unset($row['id']); return $row + parent::buildRow($entity);
return $row;
} }
/** /**
......
...@@ -89,11 +89,10 @@ public function load() { ...@@ -89,11 +89,10 @@ public function load() {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function buildHeader() { public function buildHeader() {
$row['name'] = t('Name'); $header['name'] = t('Name');
$row['roles'] = t('Roles'); $header['roles'] = t('Roles');
$row['weight'] = t('Weight'); $header['weight'] = t('Weight');
$row['operations'] = t('Operations'); return $header + parent::buildHeader();
return $row;
} }
/** /**
...@@ -118,7 +117,7 @@ public function buildRow(EntityInterface $entity) { ...@@ -118,7 +117,7 @@ public function buildRow(EntityInterface $entity) {
} }
} }
else { else {
$row['name'] = array('#markup' => String::checkPlain($entity->label())); $row['name'] = array('#markup' => $this->getLabel($entity));
$roles = array_map('\Drupal\Component\Utility\String::checkPlain', filter_get_roles_by_format($entity)); $roles = array_map('\Drupal\Component\Utility\String::checkPlain', filter_get_roles_by_format($entity));
$roles_markup = $roles ? implode(', ', $roles) : t('No roles may use this format'); $roles_markup = $roles ? implode(', ', $roles) : t('No roles may use this format');
} }
...@@ -133,8 +132,7 @@ public function buildRow(EntityInterface $entity) { ...@@ -133,8 +132,7 @@ public function buildRow(EntityInterface $entity) {
'#attributes' => array('class' => array('text-format-order-weight')), '#attributes' => array('class' => array('text-format-order-weight')),
); );
$row['operations'] = $this->buildOperations($entity); return $row + parent::buildRow($entity);
return $row;
} }
/** /**
......
...@@ -75,19 +75,16 @@ public static function createInstance(ContainerInterface $container, $entity_typ ...@@ -75,19 +75,16 @@ public static function createInstance(ContainerInterface $container, $entity_typ
* {@inheritdoc} * {@inheritdoc}
*/ */
public function buildHeader() { public function buildHeader() {
$row = parent::buildHeader(); $header['label'] = $this->translator->translate('Style name');
unset($row['id']); return $header + parent::buildHeader();
$row['label'] = $this->translator->translate('Style name');
return $row;
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function buildRow(EntityInterface $entity) { public function buildRow(EntityInterface $entity) {
$row = parent::buildRow($entity); $row['label'] = $this->getLabel($entity);
unset($row['id']); return $row + parent::buildRow($entity);
return $row;
} }
/** /**
......
...@@ -60,22 +60,16 @@ public function getOperations(EntityInterface $entity) { ...@@ -60,22 +60,16 @@ public function getOperations(EntityInterface $entity) {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function buildHeader() { public function buildHeader() {
$row = parent::buildHeader(); $header['label'] = t('Name');
unset($row['id']); $header['weight'] = t('Weight');
$row['label'] = t('Name'); return $header + parent::buildHeader();
$row['weight'] = t('Weight');
return $row;
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function buildRow(EntityInterface $entity) { public function buildRow(EntityInterface $entity) {
$row = parent::buildRow($entity);
$row['#attributes']['class'][] = 'draggable'; $row['#attributes']['class'][] = 'draggable';
unset($row['id']);
$row['label'] = array( $row['label'] = array(
'#markup' => check_plain($entity->get('label')), '#markup' => check_plain($entity->get('label')),
...@@ -92,7 +86,7 @@ public function buildRow(EntityInterface $entity) { ...@@ -92,7 +86,7 @@ public function buildRow(EntityInterface $entity) {
'#delta' => 30, '#delta' => 30,
); );
return $row; return $row + parent::buildRow($entity);
} }
/** /**
......
...@@ -18,13 +18,12 @@ class MenuListController extends ConfigEntityListController { ...@@ -18,13 +18,12 @@ class MenuListController extends ConfigEntityListController {
* Overrides \Drupal\Core\Entity\EntityListController::buildHeader(). * Overrides \Drupal\Core\Entity\EntityListController::buildHeader().
*/ */
public function buildHeader() { public function buildHeader() {
$row['title'] = t('Title'); $header['title'] = t('Title');
$row['description'] = array( $header['description'] = array(
'data' => t('Description'), 'data' => t('Description'),
'class' => array(RESPONSIVE_PRIORITY_MEDIUM), 'class' => array(RESPONSIVE_PRIORITY_MEDIUM),
); );
$row['operations'] = t('Operations'); return $header + parent::buildHeader();
return $row;
} }
/** /**
...@@ -32,12 +31,11 @@ public function buildHeader() { ...@@ -32,12 +31,11 @@ public function buildHeader() {
*/ */
public function buildRow(EntityInterface $entity) { public function buildRow(EntityInterface $entity) {
$row['title'] = array( $row['title'] = array(
'data' => check_plain($entity->label()), 'data' => $this->getLabel($entity),
'class' => array('menu-label'), 'class' => array('menu-label'),
); );
$row['description'] = filter_xss_admin($entity->description); $row['description'] = filter_xss_admin($entity->description);
$row['operations']['data'] = $this->buildOperations($entity); return $row + parent::buildRow($entity);
return $row;
} }
/** /**
......
...@@ -63,13 +63,12 @@ public static function createInstance(ContainerInterface $container, $entity_typ ...@@ -63,13 +63,12 @@ public static function createInstance(ContainerInterface $container, $entity_typ
* {@inheritdoc} * {@inheritdoc}
*/ */
public function buildHeader() { public function buildHeader() {
$row['title'] = t('Name'); $header['title'] = t('Name');
$row['description'] = array( $header['description'] = array(
'data' => t('Description'), 'data' => t('Description'),
'class' => array(RESPONSIVE_PRIORITY_MEDIUM), 'class' => array(RESPONSIVE_PRIORITY_MEDIUM),
); );
$row['operations'] = t('Operations'); return $header + parent::buildHeader();
return $row;
} }
/** /**
...@@ -77,12 +76,11 @@ public function buildHeader() { ...@@ -77,12 +76,11 @@ public function buildHeader() {
*/ */
public function buildRow(EntityInterface $entity) { public function buildRow(EntityInterface $entity) {
$row['title'] = array( $row['title'] = array(
'data' => String::checkPlain($entity->label()), 'data' => $this->getLabel($entity),
'class' => array('menu-label'), 'class' => array('menu-label'),
); );
$row['description'] = Xss::filterAdmin($entity->description); $row['description'] = Xss::filterAdmin($entity->description);
$row['operations']['data'] = $this->buildOperations($entity); return $row + parent::buildRow($entity);
return $row;
} }
/** /**
......
...@@ -16,19 +16,21 @@ ...@@ -16,19 +16,21 @@
class PictureMappingListController extends ConfigEntityListController { class PictureMappingListController extends ConfigEntityListController {
/** /**
* Overrides Drupal\config\EntityListControllerBase::hookMenu(). * {@inheritdoc}
*/ */
public function hookMenu() { public function buildHeader() {
$path = $this->entityInfo['list path']; $header['label'] = t('Label');
$items = parent::hookMenu(); $header['id'] = t('Machine name');
return $header + parent::buildHeader();
// Override the access callback. }
$items[$path]['title'] = 'Picture Mappings';
$items[$path]['description'] = 'Manage list of picture mappings.';
$items[$path]['access callback'] = 'user_access';
$items[$path]['access arguments'] = array('administer pictures');
return $items; /**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity) {
$row['label'] = $this->getLabel($entity);
$row['id'] = $entity->id();
return $row + parent::buildRow($entity);
} }
/** /**
......
...@@ -19,9 +19,8 @@ class ShortcutSetListController extends ConfigEntityListController { ...@@ -19,9 +19,8 @@ class ShortcutSetListController extends ConfigEntityListController {
* Overrides \Drupal\Core\Entity\EntityListController::buildHeader(). * Overrides \Drupal\Core\Entity\EntityListController::buildHeader().
*/ */
public function buildHeader() { public function buildHeader() {
$row['label'] = t('Name'); $header['name'] = t('Name');
$row['operations'] = t('Operations'); return $header + parent::buildHeader();
return $row;
} }
/** /**
...@@ -47,9 +46,8 @@ public function getOperations(EntityInterface $entity) { ...@@ -47,9 +46,8 @@ public function getOperations(EntityInterface $entity) {
* Overrides \Drupal\Core\Entity\EntityListController::buildRow(). * Overrides \Drupal\Core\Entity\EntityListController::buildRow().
*/ */
public function buildRow(EntityInterface $entity) { public function buildRow(EntityInterface $entity) {
$row['name'] = check_plain($entity->label()); $row['name'] = $this->getLabel($entity);
$row['operations']['data'] = $this->buildOperations($entity); return $row + parent::buildRow($entity);
return $row;
} }
} }
...@@ -76,8 +76,7 @@ public function buildHeader() { ...@@ -76,8 +76,7 @@ public function buildHeader() {
$header['id'] = t('Machine name'); $header['id'] = t('Machine name');
$header['label'] = t('Name'); $header['label'] = t('Name');
$header['pattern'] = t('Pattern'); $header['pattern'] = t('Pattern');
$header['operations'] = t('Operations'); return $header + parent::buildHeader();
return $header;
} }
/** /**
...@@ -85,10 +84,9 @@ public function buildHeader() { ...@@ -85,10 +84,9 @@ public function buildHeader() {
*/ */
public function buildRow(EntityInterface $entity) { public function buildRow(EntityInterface $entity) {
$row['id'] = $entity->id(); $row['id'] = $entity->id();
$row['label'] = String::checkPlain($entity->label()); $row['label'] = $this->getLabel($entity);
$row['pattern'] = $this->dateService->format(REQUEST_TIME, $entity->id()); $row['pattern'] = $this->dateService->format(REQUEST_TIME, $entity->id());
$row['operations']['data'] = $this->buildOperations($entity); return $row + parent::buildRow($entity);
return $row;
} }
} }
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
* module = "entity_test", * module = "entity_test",
* controllers = { * controllers = {
* "storage" = "Drupal\entity_test\EntityTestStorageController", * "storage" = "Drupal\entity_test\EntityTestStorageController",
* "list" = "Drupal\entity_test\EntityTestListController",
* "access" = "Drupal\entity_test\EntityTestAccessController", * "access" = "Drupal\entity_test\EntityTestAccessController",
* "form" = { * "form" = {
* "default" = "Drupal\entity_test\EntityTestFormController" * "default" = "Drupal\entity_test\EntityTestFormController"
......
<?php
/**
* @file
* Contains \Drupal\entity_test\EntityTestListController.
*/
namespace Drupal\entity_test;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityListController;
/**
* Provides a list controller for entity_test.
*/
class EntityTestListController extends EntityListController {
/**
* {@inheritdoc}
*/
public function buildHeader() {
$header['label'] = t('Label');
$header['id'] = t('Machine name');
return $header + parent::buildHeader();
}
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity) {
$row['label'] = $this->getLabel($entity);
$row['id'] = $entity->id();
return $row + parent::buildRow($entity);
}
}
...@@ -56,25 +56,20 @@ public function getOperations(EntityInterface $entity) { ...@@ -56,25 +56,20 @@ public function getOperations(EntityInterface $entity) {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function buildHeader() { public function buildHeader() {