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 protected function getEntityIds() {
17 $query = $this->getStorage()->getQuery()
18 ->condition('id', 'global', '<>');
20 // Only add the pager if a limit is specified.
22 $query->pager($this->limit);
25 $entity_ids = $query->execute();
27 // Load global entity always.
28 return $entity_ids + $this->getParentIds($entity_ids);
32 * Gets the parent entity ids for the list of entities to load.
34 * @param array $entity_ids
35 * The metatag entity ids.
38 * The list of parents to load
40 protected function getParentIds(array $entity_ids) {
41 $parents = ['global' => 'global'];
42 foreach ($entity_ids as $entity_id) {
43 if (strpos($entity_id, '__') !== FALSE) {
44 $entity_id_array = explode('__', $entity_id);
45 $parent = reset($entity_id_array);
46 $parents[$parent] = $parent;
49 $parents_query = $this->getStorage()->getQuery()
50 ->condition('id', $parents, 'IN');
51 return $parents_query->execute();
57 public function buildHeader() {
58 $header['label'] = $this->t('Type');
59 return $header + parent::buildHeader();
65 public function buildRow(EntityInterface $entity) {
66 $row['label'] = $this->getLabelAndConfig($entity);
67 return $row + parent::buildRow($entity);
73 public function getOperations(EntityInterface $entity) {
74 $operations = parent::getOperations($entity);
76 // Global and entity defaults can be reverted but not deleted.
77 if (in_array($entity->id(), MetatagManager::protectedDefaults())) {
78 unset($operations['delete']);
79 $operations['revert'] = [
80 'title' => t('Revert'),
81 'weight' => $operations['edit']['weight'] + 1,
82 'url' => $entity->toUrl('revert-form'),
90 * Renders the Metatag defaults label plus its configuration.
92 * @param \Drupal\Core\Entity\EntityInterface $entity
93 * The Metatag defaults entity.
96 * Render array for a table cell.
98 public function getLabelAndConfig(EntityInterface $entity) {
102 if ($entity->id() != 'global') {
103 $prefix = '<div class="indentation"></div>';
104 $inherits .= 'Global';
106 if (strpos($entity->id(), '__') !== FALSE) {
107 $prefix .= '<div class="indentation"></div>';
108 list($entity_label, $bundle_label) = explode(': ', $entity->get('label'));
109 $inherits .= ', ' . $entity_label;
112 if (!empty($inherits)) {
113 $output .= '<div><p>' . t('Inherits meta tags from: @inherits', [
114 '@inherits' => $inherits,
117 $tags = $entity->get('tags');
121 foreach ($tags as $tag_id => $tag_value) {
122 $output .= '<tr><td>' . $tag_id . ':</td><td>' . $tag_value . '</td></tr>';
124 $output .= '</tbody></table>';
127 $output .= '</div></div>';
131 '#type' => 'details',
132 '#prefix' => $prefix,
133 '#title' => $entity->label(),
135 '#markup' => $output,