Browse Source

Step 1: create the module and content entity class.

Frederic G. MARAND 8 years ago
parent
commit
c1a3bb3146
3 changed files with 79 additions and 1 deletions
  1. 22 1
      README.md
  2. 6 0
      dr8_zth.info.yml
  3. 51 0
      src/Entity/Blog.php

+ 22 - 1
README.md

@@ -1 +1,22 @@
-Demonstrate various Drupal 8 features.
+# Demonstrate various Drupal 8 features.
+## "blog" branch
+
+This contains a solution to the exercise for the entity chapter. The exercise is
+the following:
+
+* Create a `Blog` entity and a `BlogType` entity as its bundle entity. Blogs are
+  entities created by a `User`. Various bundles could be a traditional blog, an
+  image gallery and a vlog. 
+* Blog items (instances of the `Blog` entity) should be translatable and 
+  revisioned by default. 
+* Access control to the `Blog` entity should be at the entity type level 
+  (`Blog`), not the entity bundle level (`BlogType`).
+* Both should have a complete CRUD UI: list, display, add/edit, delete
+* Blogs must appear as tabs under the user profile page, with sub-tabs per blog
+  type
+* To better understand what's going on, it is probably better _not_ to use the
+  Drupal console `generate` commands.
+
+### Steps
+
+1. Create the module and a `Blog` content entity in it.

+ 6 - 0
dr8_zth.info.yml

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

+ 51 - 0
src/Entity/Blog.php

@@ -0,0 +1,51 @@
+<?php
+
+namespace Drupal\dr8_zth\Entity;
+
+
+use Drupal\Core\Entity\ContentEntityBase;
+
+/**
+ * Class Blog defines the Blog entity class.
+ *
+ * @ContentEntityType(
+ *   id = "blog",
+ *   label = @Translation("Blog"),
+ *   label_singular = @Translation("blog item"),
+ *   label_plural = @Translation("blog items"),
+ *   label_count = @PluralTranslation(
+ *     singular = "@count blog item",
+ *     plural = "@count blog items"
+ *   ),
+ *   bundle_label = @Translation("Blog type"),
+ *   base_table = "blog",
+ *   data_table = "blog_field_data",
+ *   revision_table = "blog_revision",
+ *   revision_data_table = "blog_field_revision",
+ *   translatable = TRUE,
+ *   list_cache_contexts = {},
+ *   entity_keys = {
+ *     "id" = "blog_id",
+ *     "revision" = "blog_vid",
+ *     "bundle" = "type",
+ *     "label" = "title",
+ *     "langcode" = "langcode",
+ *     "uuid" = "uuid",
+ *     "status" = "status",
+ *     "author" = "uid",
+ *   },
+ *   bundle_entity_type = "node_type",
+ *   field_ui_base_route = "entity.blog_type.edit_form",
+ *   permission_granularity = "entity_type",
+ *   links = {
+ *     "canonical" = "/blog/{blog}",
+ *     "delete-form" = "/blog/{blog}/delete",
+ *     "edit-form" = "/blog/{blog}/edit",
+ *     "version-history" = "/blog/{blog}/revisions",
+ *     "revision" = "/blog/{blog}/revisions/{blog_revision}/view",
+ *   }
+ * )
+ */
+class Blog extends ContentEntityBase {
+
+}