3 namespace Drupal\metatag;
5 use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
6 use Drupal\Core\Entity\EntityInterface;
9 * Provides a listing of Metatag defaults entities.
11 class MetatagDefaultsListBuilder extends ConfigEntityListBuilder {
16 public function load() {
17 $entities = parent::load();
18 // Move the Global defaults to the top.
19 return ['global' => $entities['global']] + $entities;
25 public function buildHeader() {
26 $header['label'] = $this->t('Type');
27 return $header + parent::buildHeader();
33 public function buildRow(EntityInterface $entity) {
34 $row['label'] = $this->getLabelAndConfig($entity);
35 return $row + parent::buildRow($entity);
41 public function getOperations(EntityInterface $entity) {
42 $operations = parent::getOperations($entity);
44 // Set the defaults that should not be deletable
45 $protected_defaults = ['global', '403', '404', 'node', 'front', 'taxonomy_term', 'user'];
47 // Global and entity defaults can be reverted but not deleted.
48 if (in_array($entity->id(), $protected_defaults)) {
49 unset($operations['delete']);
50 $operations['revert'] = [
51 'title' => t('Revert'),
52 'weight' => $operations['edit']['weight'] + 1,
53 'url' => $entity->toUrl('revert-form'),
61 * Renders the Metatag defaults label plus its configuration.
63 * @param EntityInterface $entity
64 * The Metatag defaults entity.
67 * Render array for a table cell.
69 public function getLabelAndConfig(EntityInterface $entity) {
73 if ($entity->id() != 'global') {
74 $prefix = '<div class="indentation"></div>';
75 $inherits .= 'Global';
77 if (strpos($entity->id(), '__') !== FALSE) {
78 $prefix .= '<div class="indentation"></div>';
79 list($entity_label, $bundle_label) = explode(': ', $entity->get('label'));
80 $inherits .= ', ' . $entity_label;
83 if (!empty($inherits)) {
84 $output .= '<div><p>' . t('Inherits meta tags from: @inherits', ['@inherits' => $inherits]) . '</p></div>';
86 $tags = $entity->get('tags');
90 foreach ($tags as $tag_id => $tag_value) {
91 $output .= '<tr><td>' . $tag_id . ':</td><td>' . $tag_value . '</td></tr>';
93 $output .= '</tbody></table>';
96 $output .= '</div></div>';
100 '#type' => 'details',
101 '#prefix' => $prefix,
102 '#title' => $entity->label(),
104 '#markup' => $output,