Browse Source

Step 4: complete implementation of the BlogType collection route

Frederic G. MARAND 7 years ago
parent
commit
7214eb6df9
4 changed files with 44 additions and 3 deletions
  1. 2 1
      README.md
  2. 1 1
      dr8_zth.routing.yml
  3. 40 0
      src/BlogTypeListBuilder.php
  4. 1 1
      src/Entity/BlogType.php

+ 2 - 1
README.md

@@ -25,4 +25,5 @@ the following:
 3. Implement skeletons for add/edit/delete forms and implement a `BlogType`
   config entity schema to be able to test config import/export and the delete
   form
-  
+4. Complete the implementation of the `BlogType` collection route to show type,
+  name, description, and operations.

+ 1 - 1
dr8_zth.routing.yml

@@ -2,7 +2,7 @@ entity.blog_type.collection:
   path: '/admin/structure/blog'
   defaults:
     _entity_list: 'blog_type'
-    _title: 'Blogs'
+    _title: 'Blog types'
   requirements:
     _permission: 'administer blog'
 

+ 40 - 0
src/BlogTypeListBuilder.php

@@ -0,0 +1,40 @@
+<?php
+
+namespace Drupal\dr8_zth;
+
+use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
+use Drupal\Core\Entity\EntityInterface;
+
+/**
+ * Class BlogTypeListBuilder is the list builder for BlogType entities.
+ */
+class BlogTypeListBuilder extends ConfigEntityListBuilder {
+  /**
+   * {@inheritdoc}
+   */
+  public function buildHeader() {
+    $parentHeader = parent::buildHeader();
+    $header = [
+      $this->t('Type'),
+      $this->t('Name'),
+      $this->t('Description'),
+    ];
+    $ret = array_merge($header, $parentHeader);
+    return $ret;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function buildRow(EntityInterface $entity) {
+    assert($entity instanceof BlogTypeInterface);
+
+    $row = [
+      $entity->label(),
+      $entity->id(),
+      $entity->getDescription(),
+    ];
+    $ret = array_merge($row, parent::buildRow($entity));
+    return $ret;
+  }
+}

+ 1 - 1
src/Entity/BlogType.php

@@ -16,7 +16,7 @@ use Drupal\dr8_zth\BlogTypeInterface;
  *       "default" = "Drupal\dr8_zth\Form\BlogTypeForm",
  *       "delete" = "Drupal\dr8_zth\Form\BlogTypeDeleteForm"
  *     },
- *     "list_builder" = "Drupal\Core\Config\Entity\ConfigEntityListBuilder",
+ *     "list_builder" = "Drupal\dr8_zth\BlogTypeListBuilder",
  *   },
  *   admin_permission = "administer blog",
  *   config_prefix = "type",