diff --git a/src/Form/ContentEntityFormWithRevisions.php b/src/Form/ContentEntityFormWithRevisions.php index 8ded451e070f266dc784ccd8957b5139ee9b6657..906eb354cb5f9486d09a2602069e71e880ac743e 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 c20ef335f0c3530f2704266f24cb8c123b2e1b8b..d4539912532484122d64f1b9a3e42f256d4fc693 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 765c43ea017daa4f06e2f988fe74ccda00952ab3..975afb2193a150ac9c31abcc2357710e05c62139 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 afe49a7d4b231d4072d6751f7ba8f067c4c6e179..efa095b4b3fa44c454b5e48bb601bfa2e1b5b0cb 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; + } + }