From 3b01b6e345c5a2f2569afa6a5de14c6ce49c686c Mon Sep 17 00:00:00 2001
From: Daniel Wehner <daniel@tag1consulting.com>
Date: Sun, 14 Feb 2016 18:56:30 +0100
Subject: [PATCH] Address feedback from bojanz

---
 ....php => RevisionableContentEntityForm.php} | 21 ++++++++++++-------
 .../src/Entity/EnhancedEntity.php             |  4 ++--
 2 files changed, 16 insertions(+), 9 deletions(-)
 rename src/Form/{ContentEntityFormWithRevisions.php => RevisionableContentEntityForm.php} (90%)

diff --git a/src/Form/ContentEntityFormWithRevisions.php b/src/Form/RevisionableContentEntityForm.php
similarity index 90%
rename from src/Form/ContentEntityFormWithRevisions.php
rename to src/Form/RevisionableContentEntityForm.php
index 906eb35..2c33f1b 100644
--- a/src/Form/ContentEntityFormWithRevisions.php
+++ b/src/Form/RevisionableContentEntityForm.php
@@ -2,7 +2,7 @@
 
 /**
  * @file
- * Contains \Drupal\entity\Form\ContentEntityFormWithRevisions.
+ * Contains \Drupal\entity\Form\RevisionableContentEntityForm.
  */
 
 namespace Drupal\entity\Form;
@@ -11,7 +11,10 @@ use Drupal\Core\Entity\ContentEntityForm;
 use Drupal\Core\Form\FormStateInterface;
 use Drupal\entity\Entity\RevisionableEntityBundleInterface;
 
-class ContentEntityFormWithRevisions extends ContentEntityForm {
+/**
+ * Extends the base entity form with revision support in the UI.
+ */
+class RevisionableContentEntityForm extends ContentEntityForm {
 
   /**
    * The entity being used by this form.
@@ -39,20 +42,24 @@ class ContentEntityFormWithRevisions extends ContentEntityForm {
     }
   }
 
+  /**
+   * Returns the bundle entity of the entity, or NULL if there is none.
+   *
+   * @return \Drupal\Core\Entity\EntityInterface|null
+   */
   protected function getBundleEntity() {
-    $bundle_entity = $this->entity->{$this->entity->getEntityType()->getKey('bundle')}->referencedEntities()[0];
-    return $bundle_entity;
+    if ($bundle_key = $this->entity->getEntityType()->getKey('bundle')) {
+      return $this->entity->{$bundle_key}->referencedEntities()[0];
+    }
+    return NULL;
   }
 
   /**
    * {@inheritdoc}
    */
   public function form(array $form, FormStateInterface $form_state) {
-
     $entity_type = $this->entity->getEntityType();
-
     $bundle_entity = $this->getBundleEntity();
-
     $account = $this->currentUser();
 
     if ($this->operation == 'edit') {
diff --git a/tests/modules/entity_module_test/src/Entity/EnhancedEntity.php b/tests/modules/entity_module_test/src/Entity/EnhancedEntity.php
index 975afb2..267e2ce 100644
--- a/tests/modules/entity_module_test/src/Entity/EnhancedEntity.php
+++ b/tests/modules/entity_module_test/src/Entity/EnhancedEntity.php
@@ -22,8 +22,8 @@ use Drupal\entity\Revision\EntityRevisionLogTrait;
  *   handlers = {
  *     "storage" = "\Drupal\Core\Entity\Sql\SqlContentEntityStorage",
  *     "form" = {
- *       "add" = "\Drupal\entity\Form\ContentEntityFormWithRevisions",
- *       "edit" = "\Drupal\entity\Form\ContentEntityFormWithRevisions",
+ *       "add" = "\Drupal\entity\Form\RevisionableContentEntityForm",
+ *       "edit" = "\Drupal\entity\Form\RevisionableContentEntityForm",
  *       "delete" = "\Drupal\Core\Entity\EntityDeleteForm",
  *     },
  *     "route_provider" = {
-- 
GitLab