Browse Source

Step 2: create a config entity class as the bundle class for the content class.

Frederic G. MARAND 8 years ago
parent
commit
ff7a554bfd
7 changed files with 74 additions and 6 deletions
  1. 2 0
      README.md
  2. 4 3
      dr8_zth.info.yml
  3. 5 0
      dr8_zth.links.menu.yml
  4. 4 0
      dr8_zth.permissions.yml
  5. 8 0
      dr8_zth.routing.yml
  6. 12 3
      src/Entity/Blog.php
  7. 39 0
      src/Entity/BlogType.php

+ 2 - 0
README.md

@@ -20,3 +20,5 @@ the following:
 ### Steps
 
 1. Create the module and a `Blog` content entity in it.
+2. Create a `BlogType` config entity as the bundle entity for `Blog`, enabling
+  its collection route.

+ 4 - 3
dr8_zth.info.yml

@@ -1,6 +1,7 @@
-name: 'DR8 ZTH'
-description: 'Drupal 8 Zero-to-Hero course'
-package: 'OSInet Formation'
+name: DR8 ZTH
+description: Drupal 8 Zero-to-Hero course
+package: OSInet Formation
 core: 8.x
 php: 7.0
 type: module
+

+ 5 - 0
dr8_zth.links.menu.yml

@@ -0,0 +1,5 @@
+entity.blog_type.collection:
+  title: Blogging
+  parent: system.admin_structure
+  description: 'Manage the blogging system.'
+  route_name: entity.blog_type.collection

+ 4 - 0
dr8_zth.permissions.yml

@@ -0,0 +1,4 @@
+administer blog:
+  title: 'Administer the blog system'
+  description: 'Administer both blog types and blog items'
+  restrict access: true

+ 8 - 0
dr8_zth.routing.yml

@@ -0,0 +1,8 @@
+entity.blog_type.collection:
+  path: '/admin/structure/blog'
+  defaults:
+    _entity_list: 'blog_type'
+    _title: 'Blogs'
+  requirements:
+    _permission: 'administer blog'
+

+ 12 - 3
src/Entity/Blog.php

@@ -34,16 +34,25 @@ use Drupal\Core\Entity\ContentEntityBase;
  *     "status" = "status",
  *     "author" = "uid",
  *   },
- *   bundle_entity_type = "node_type",
+ *   handlers = {
+ *     "route_provider" = {
+ *       "html" = "Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider",
+ *     }
+ *   },
+ *   bundle_entity_type = "blog_type",
  *   field_ui_base_route = "entity.blog_type.edit_form",
  *   permission_granularity = "entity_type",
  *   links = {
+ *     "add-form" = "/admin/content/blog/add/{blog_type}",
+ *     "add-page" = "/admin/content/blog/add",
  *     "canonical" = "/blog/{blog}",
+ *     "collection" = "/admin/content/blog",
  *     "delete-form" = "/blog/{blog}/delete",
  *     "edit-form" = "/blog/{blog}/edit",
- *     "version-history" = "/blog/{blog}/revisions",
  *     "revision" = "/blog/{blog}/revisions/{blog_revision}/view",
- *   }
+ *     "version-history" = "/blog/{blog}/revisions"
+ *   },
+ *   admin_permission = "administer blog",
  * )
  */
 class Blog extends ContentEntityBase {

+ 39 - 0
src/Entity/BlogType.php

@@ -0,0 +1,39 @@
+<?php
+
+namespace Drupal\dr8_zth\Entity;
+
+
+use Drupal\Core\Config\Entity\ConfigEntityBase;
+
+/**
+ * Defines the taxonomy vocabulary entity.
+ *
+ * @ConfigEntityType(
+ *   id = "blog_type",
+ *   label = @Translation("Blog type"),
+ *   handlers = {
+ *     "list_builder" = "Drupal\Core\Config\Entity\ConfigEntityListBuilder",
+ *   },
+ *   admin_permission = "administer blog",
+ *   config_prefix = "type",
+ *   bundle_of = "blog",
+ *   entity_keys = {
+ *     "id" = "type",
+ *     "label" = "name",
+ *   },
+ *   links = {
+ *     "add-form" = "/admin/structure/blog/manage/{blog_type}/add",
+ *     "collection" = "/admin/structure/blog",
+ *     "delete-form" = "/admin/structure/blog/manage/{blog_type}/delete",
+ *     "edit-form" = "/admin/structure/blog/manage/{blog_type}"
+ *   },
+ *   config_export = {
+ *     "name",
+ *     "type",
+ *     "description",
+ *   }
+ * )
+ */
+class BlogType extends ConfigEntityBase {
+
+}