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();
19 // Move the Global defaults to the top. Don't assume that the global config
20 // exists, it might have been removed.
21 if (isset($entities['global'])) {
22 return ['global' => $entities['global']] + $entities;
32 public function buildHeader() {
33 $header['label'] = $this->t('Type');
34 return $header + parent::buildHeader();
40 public function buildRow(EntityInterface $entity) {
41 $row['label'] = $this->getLabelAndConfig($entity);
42 return $row + parent::buildRow($entity);
48 public function getOperations(EntityInterface $entity) {
49 $operations = parent::getOperations($entity);
51 // Global and entity defaults can be reverted but not deleted.
52 if (in_array($entity->id(), MetatagManager::protectedDefaults())) {
53 unset($operations['delete']);
54 $operations['revert'] = [
55 'title' => t('Revert'),
56 'weight' => $operations['edit']['weight'] + 1,
57 'url' => $entity->toUrl('revert-form'),
65 * Renders the Metatag defaults label plus its configuration.
67 * @param Drupal\Core\Entity\EntityInterface $entity
68 * The Metatag defaults entity.
71 * Render array for a table cell.
73 public function getLabelAndConfig(EntityInterface $entity) {
77 if ($entity->id() != 'global') {
78 $prefix = '<div class="indentation"></div>';
79 $inherits .= 'Global';
81 if (strpos($entity->id(), '__') !== FALSE) {
82 $prefix .= '<div class="indentation"></div>';
83 list($entity_label, $bundle_label) = explode(': ', $entity->get('label'));
84 $inherits .= ', ' . $entity_label;
87 if (!empty($inherits)) {
88 $output .= '<div><p>' . t('Inherits meta tags from: @inherits', [
89 '@inherits' => $inherits,
92 $tags = $entity->get('tags');
96 foreach ($tags as $tag_id => $tag_value) {
97 $output .= '<tr><td>' . $tag_id . ':</td><td>' . $tag_value . '</td></tr>';
99 $output .= '</tbody></table>';
102 $output .= '</div></div>';
106 '#type' => 'details',
107 '#prefix' => $prefix,
108 '#title' => $entity->label(),
110 '#markup' => $output,