diff --git a/core/lib/Drupal/Core/Entity/Form/RevisionableContentEntityForm.php b/core/lib/Drupal/Core/Entity/Form/RevisionableContentEntityForm.php index 5760a8e..2d551d6 100644 --- a/core/lib/Drupal/Core/Entity/Form/RevisionableContentEntityForm.php +++ b/core/lib/Drupal/Core/Entity/Form/RevisionableContentEntityForm.php @@ -29,15 +29,10 @@ class RevisionableContentEntityForm extends ContentEntityForm { protected function prepareEntity() { parent::prepareEntity(); - $bundle_entity = $this->getBundleEntity(); // Set up default values, if required. if (!$this->entity->isNew()) { $this->entity->setRevisionLogMessage(NULL); } - if ($bundle_entity instanceof RevisionableEntityBundleInterface) { - // Always use the default revision setting. - $this->entity->setNewRevision($bundle_entity && $bundle_entity->shouldCreateNewRevision()); - } } /** @@ -70,6 +65,14 @@ public function form(array $form, FormStateInterface $form_state) { '#attributes' => array('class' => array('entity-meta')), '#weight' => 99, ]; + + $new_revision_default = FALSE; + $bundle_entity = $this->getBundleEntity(); + if ($bundle_entity instanceof RevisionableEntityBundleInterface) { + // Always use the default revision setting. + $new_revision_default = $bundle_entity->shouldCreateNewRevision(); + } + // Add a log field if the "Create new revision" option is checked, or if the // current user has the ability to check that option. // @todo Could we autogenerate this form by using some widget on the @@ -78,24 +81,25 @@ public function form(array $form, FormStateInterface $form_state) { '#type' => 'details', '#title' => $this->t('Revision information'), // Open by default when "Create new revision" is checked. - '#open' => $this->entity->isNewRevision(), + '#open' => $new_revision_default, '#group' => 'advanced', '#weight' => 20, - '#access' => $this->entity->isNewRevision() || ($entity_type->get('admin_permission')) && $account->hasPermission($entity_type->get('admin_permission')), + '#access' => $new_revision_default || ($entity_type->get('admin_permission')) && $account->hasPermission($entity_type->get('admin_permission')), '#optional' => TRUE, ]; $form['revision'] = [ '#type' => 'checkbox', '#title' => $this->t('Create new revision'), - '#default_value' => $this->entity->isNewRevision(), + '#default_value' => $new_revision_default, '#access' => !$this->entity->isNew() && ($entity_type->get('admin_permission') || $account->hasPermission($entity_type->get('admin_permission'))), '#group' => 'revision_information', ]; + // Check the revision log checkbox when the log textarea is filled in. // This must not happen if "Create new revision" is enabled by default, // since the state would auto-disable the checkbox otherwise. if (!$this->entity->isNewRevision()) { - $form['revision_information']['revision']['#states'] = [ + $form['revision']['#states'] = [ 'checked' => [ 'textarea[name="revision_log"]' => ['empty' => FALSE], ], diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateTest.php index 23cf034..befa0f0 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateTest.php @@ -102,6 +102,9 @@ public function testEntityTypeUpdateWithoutData() { $expected = array( 'entity_test_update' => array( t('The %entity_type entity type needs to be updated.', ['%entity_type' => $this->entityManager->getDefinition('entity_test_update')->getLabel()]), + // The revision key is now defined, so the revision field needs to be + // created. + t('The %field_name field needs to be installed.', ['%field_name' => 'Revision ID']), ), ); $this->assertEqual($this->entityDefinitionUpdateManager->getChangeSummary(), $expected); //, 'EntityDefinitionUpdateManager reports the expected change summary.');