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 906eb354cb5f9486d09a2602069e71e880ac743e..2c33f1b10ba812956eb67bab31b0f2d9705eaacf 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 975afb2193a150ac9c31abcc2357710e05c62139..267e2cef2bdc1148b754b60a96b9f5765e07e623 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" = {