From 8018260c4791b3c336f663be5917f36ce4c57a30 Mon Sep 17 00:00:00 2001 From: Daniel Wehner <daniel@tag1consulting.com> Date: Tue, 26 Jan 2016 13:22:54 +0100 Subject: [PATCH] Expand the tests a bit to use the new base form class --- src/Form/ContentEntityFormWithRevisions.php | 8 +++++++- .../config/schema/entity_module_test.schema.yml | 3 +++ .../src/Entity/EnhancedEntity.php | 4 ++-- .../src/Entity/EnhancedEntityBundle.php | 17 ++++++++++++++++- 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/Form/ContentEntityFormWithRevisions.php b/src/Form/ContentEntityFormWithRevisions.php index 8ded451..906eb35 100644 --- a/src/Form/ContentEntityFormWithRevisions.php +++ b/src/Form/ContentEntityFormWithRevisions.php @@ -138,7 +138,13 @@ class ContentEntityFormWithRevisions extends ContentEntityForm { if ($this->entity->id()) { $form_state->setValue('id', $this->entity->id()); $form_state->set('id', $this->entity->id()); - $form_state->setRedirectUrl($this->entity->urlInfo('collection')); + + if ($this->entity->getEntityType()->hasLinkTemplate('collection')) { + $form_state->setRedirectUrl($this->entity->toUrl('collection')); + } + else { + $form_state->setRedirectUrl($this->entity->toUrl('canonical')); + } } else { // In the unlikely case something went wrong on save, the entity will be diff --git a/tests/modules/entity_module_test/config/schema/entity_module_test.schema.yml b/tests/modules/entity_module_test/config/schema/entity_module_test.schema.yml index c20ef33..d453991 100644 --- a/tests/modules/entity_module_test/config/schema/entity_module_test.schema.yml +++ b/tests/modules/entity_module_test/config/schema/entity_module_test.schema.yml @@ -11,3 +11,6 @@ entity_module_test.entity_test_enhanced_bundle.*: description: type: text label: 'Description' + new_revision: + type: boolean + label: 'New revision' diff --git a/tests/modules/entity_module_test/src/Entity/EnhancedEntity.php b/tests/modules/entity_module_test/src/Entity/EnhancedEntity.php index 765c43e..975afb2 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\Core\Entity\ContentEntityForm", - * "edit" = "\Drupal\Core\Entity\ContentEntityForm", + * "add" = "\Drupal\entity\Form\ContentEntityFormWithRevisions", + * "edit" = "\Drupal\entity\Form\ContentEntityFormWithRevisions", * "delete" = "\Drupal\Core\Entity\EntityDeleteForm", * }, * "route_provider" = { diff --git a/tests/modules/entity_module_test/src/Entity/EnhancedEntityBundle.php b/tests/modules/entity_module_test/src/Entity/EnhancedEntityBundle.php index afe49a7..efa095b 100644 --- a/tests/modules/entity_module_test/src/Entity/EnhancedEntityBundle.php +++ b/tests/modules/entity_module_test/src/Entity/EnhancedEntityBundle.php @@ -9,6 +9,7 @@ namespace Drupal\entity_module_test\Entity; use Drupal\Core\Config\Entity\ConfigEntityBundleBase; use Drupal\entity\Entity\EntityDescriptionInterface; +use Drupal\entity\Entity\RevisionableEntityBundleInterface; /** * Provides bundles for the test entity. @@ -38,7 +39,7 @@ use Drupal\entity\Entity\EntityDescriptionInterface; * }, * ) */ -class EnhancedEntityBundle extends ConfigEntityBundleBase implements EntityDescriptionInterface { +class EnhancedEntityBundle extends ConfigEntityBundleBase implements EntityDescriptionInterface, RevisionableEntityBundleInterface { /** * The bundle ID. @@ -61,6 +62,13 @@ class EnhancedEntityBundle extends ConfigEntityBundleBase implements EntityDescr */ protected $description; + /** + * Should new entities of this bundle have a new revision by default. + * + * @var bool + */ + protected $new_revision = FALSE; + /** * {@inheritdoc} */ @@ -76,4 +84,11 @@ class EnhancedEntityBundle extends ConfigEntityBundleBase implements EntityDescr return $this; } + /** + * {@inheritdoc} + */ + public function shouldCreateNewRevision() { + return $this->new_revision; + } + } -- GitLab