Skip to content
Snippets Groups Projects
Commit 3b01b6e3 authored by Daniel Wehner's avatar Daniel Wehner
Browse files

Address feedback from bojanz

parent 8018260c
No related branches found
No related tags found
No related merge requests found
......@@ -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') {
......
......@@ -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" = {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment