diff --git a/core/modules/media_entity/js/media_form.js b/core/modules/media_entity/js/media_form.js index e8c9547..fe7937a 100644 --- a/core/modules/media_entity/js/media_form.js +++ b/core/modules/media_entity/js/media_form.js @@ -18,21 +18,6 @@ Drupal.behaviors.mediaDetailsSummaries = { attach: function (context) { var $context = $(context); - $context.find('.media-form-revision-information').drupalSetSummary(function (context) { - var $revisionContext = $(context); - var revisionCheckbox = $revisionContext.find('.js-form-item-revision input'); - - // Return 'New revision' if the 'Create new revision' checkbox is - // checked, or if the checkbox doesn't exist, but the revision log does. - // For users without the "Administer content" permission the checkbox - // won't appear, but the revision log will if the content type is set to - // auto-revision. - if (revisionCheckbox.is(':checked') || (!revisionCheckbox.length && $revisionContext.find('.js-form-item-revision-log textarea').length)) { - return Drupal.t('New revision'); - } - - return Drupal.t('No revision'); - }); $context.find('.media-form-author').drupalSetSummary(function (context) { var $authorContext = $(context); diff --git a/core/modules/media_entity/src/Entity/Media.php b/core/modules/media_entity/src/Entity/Media.php index 74eef3b..326bcf5 100644 --- a/core/modules/media_entity/src/Entity/Media.php +++ b/core/modules/media_entity/src/Entity/Media.php @@ -46,6 +46,7 @@ * revision_data_table = "media_field_revision", * translatable = TRUE, * render_cache = TRUE, + * show_revision_ui = TRUE, * entity_keys = { * "id" = "mid", * "revision" = "vid", @@ -354,7 +355,16 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { ->setLabel(t('Revision Log')) ->setDescription(t('The log entry explaining the changes in this revision.')) ->setRevisionable(TRUE) - ->setTranslatable(TRUE); + ->setTranslatable(TRUE) + ->setDefaultValue('') + ->setDisplayOptions('form', array( + 'type' => 'string_textarea', + 'weight' => 25, + 'settings' => array( + 'rows' => 4, + ), + )); + return $fields; } diff --git a/core/modules/media_entity/src/Entity/MediaBundle.php b/core/modules/media_entity/src/Entity/MediaBundle.php index 12315ce..501af38 100644 --- a/core/modules/media_entity/src/Entity/MediaBundle.php +++ b/core/modules/media_entity/src/Entity/MediaBundle.php @@ -127,7 +127,7 @@ class MediaBundle extends ConfigEntityBundleBase implements MediaBundleInterface */ public $field_map = []; - /* + /** * {@inheritdoc} */ public function getPluginCollections() { diff --git a/core/modules/media_entity/src/MediaBundleInterface.php b/core/modules/media_entity/src/MediaBundleInterface.php index da63ca4..02d5da2 100644 --- a/core/modules/media_entity/src/MediaBundleInterface.php +++ b/core/modules/media_entity/src/MediaBundleInterface.php @@ -4,11 +4,12 @@ use Drupal\Core\Config\Entity\ConfigEntityInterface; use Drupal\Core\Entity\EntityDescriptionInterface; +use Drupal\Core\Entity\RevisionableEntityBundleInterface; /** * Provides an interface defining a media bundle entity. */ -interface MediaBundleInterface extends ConfigEntityInterface, EntityDescriptionInterface { +interface MediaBundleInterface extends ConfigEntityInterface, EntityDescriptionInterface, RevisionableEntityBundleInterface { /** * Returns the label. @@ -70,14 +71,6 @@ public function setTypeConfiguration(array $configuration); public function getStatus(); /** - * Gets whether a new revision should be created by default. - * - * @return bool - * TRUE if a new revision should be created by default. - */ - public function shouldCreateNewRevision(); - - /** * Sets whether a new revision should be created by default. * * @param bool $new_revision diff --git a/core/modules/media_entity/src/MediaForm.php b/core/modules/media_entity/src/MediaForm.php index 7650afd..eceee12 100644 --- a/core/modules/media_entity/src/MediaForm.php +++ b/core/modules/media_entity/src/MediaForm.php @@ -32,7 +32,6 @@ protected function prepareEntity() { // Set up default values, if required. if (!$this->getEntity()->isNew()) { - $this->entity->setRevisionLogMessage(NULL); $this->entity->setOwnerId($this->currentUser()->id()); $this->entity->setCreatedTime(\Drupal::time()->getRequestTime()); } @@ -43,11 +42,8 @@ protected function prepareEntity() { */ public function form(array $form, FormStateInterface $form_state) { $form = parent::form($form, $form_state); - $entity_type = $this->getEntity()->getEntityType(); /** @var \Drupal\media_entity\Entity\MediaBundle $bundle_entity */ $bundle_entity = $this->entity->bundle->entity; - $account = $this->currentUser(); - $new_revision = $this->entity->bundle->entity->shouldCreateNewRevision(); if ($this->operation == 'edit') { $form['#title'] = $this->t('Edit %bundle_label @label', [ @@ -56,52 +52,6 @@ public function form(array $form, FormStateInterface $form_state) { ]); } - $form['advanced'] = [ - '#type' => 'vertical_tabs', - '#weight' => 99, - ]; - - // Add a log field if the "Create new revision" option is checked, or if the - // current user has the ability to check that option. - $form['revision_information'] = [ - '#type' => 'details', - '#title' => $this->t('Revision information'), - // Open by default when "Create new revision" is checked. - '#open' => $new_revision, - '#group' => 'advanced', - '#weight' => 20, - '#access' => $new_revision || $account->hasPermission($entity_type->get('admin_permission')), - '#attributes' => [ - 'class' => ['media-form-revision-information'], - ], - ]; - - $form['revision_information']['revision'] = [ - '#type' => 'checkbox', - '#title' => $this->t('Create new revision'), - '#default_value' => $new_revision, - '#access' => $account->hasPermission($entity_type->get('admin_permission')), - ]; - - // 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 (!$new_revision) { - $form['revision_information']['revision']['#states'] = [ - 'checked' => [ - 'textarea[name="revision_log"]' => ['empty' => FALSE], - ], - ]; - } - - $form['revision_information']['revision_log'] = [ - '#type' => 'textarea', - '#title' => $this->t('Revision log message'), - '#rows' => 4, - '#default_value' => $this->entity->getRevisionLogMessage(), - '#description' => $this->t('Briefly describe the changes you have made.'), - ]; - // Media author information for administrators. if (isset($form['uid']) || isset($form['created'])) { $form['author'] = [ @@ -215,12 +165,6 @@ public function updateStatus($entity_type_id, MediaInterface $media, array $form * {@inheritdoc} */ public function save(array $form, FormStateInterface $form_state) { - // Save as a new revision if requested to do so. - if (!$form_state->isValueEmpty('revision')) { - $this->entity->setNewRevision(); - $this->entity->setRevisionUserId($this->currentUser()->id()); - } - $insert = $this->entity->isNew(); $this->entity->save(); $context = ['@type' => $this->entity->bundle(), '%label' => $this->entity->label()]; diff --git a/core/modules/media_entity/tests/src/Functional/MediaUiFunctionalTest.php b/core/modules/media_entity/tests/src/Functional/MediaUiFunctionalTest.php index 3116e32..a1d944f 100644 --- a/core/modules/media_entity/tests/src/Functional/MediaUiFunctionalTest.php +++ b/core/modules/media_entity/tests/src/Functional/MediaUiFunctionalTest.php @@ -46,18 +46,18 @@ public function testMediaWithOnlyOneBundle() { $assert_session = $this->assertSession(); /** @var \Drupal\media_entity\MediaBundleInterface $bundle */ - $bundle = $this->drupalCreateMediaBundle(['new_revision' => TRUE]); + $bundle = $this->drupalCreateMediaBundle(['new_revision' => FALSE]); $this->drupalGet('media/add'); $assert_session->statusCodeEquals(200); $assert_session->addressEquals('media/add/' . $bundle->id()); - $assert_session->checkboxChecked('edit-revision'); + $assert_session->elementNotExists('css', '#edit-revision'); // Tests media item add form. $media_name = $this->randomMachineName(); $page->fillField('name[0][value]', $media_name); $revision_log_message = $this->randomString(); - $page->fillField('revision_log', $revision_log_message); + $page->fillField('revision_log[0][value]', $revision_log_message); $page->pressButton('Save and publish'); $media_id = $this->container->get('entity.query')->get('media')->execute(); $media_id = reset($media_id); @@ -102,7 +102,7 @@ public function testMediaWithOnlyOneBundle() { $this->drupalGet('media/' . $media_id . '/edit'); $assert_session->checkboxChecked('edit-revision'); $page->fillField('name[0][value]', $media_name); - $page->fillField('revision_log', $revision_log_message); + $page->fillField('revision_log[0][value]', $revision_log_message); $page->pressButton('Save and keep published'); $assert_session->titleEquals($media_name . ' | Drupal'); /** @var \Drupal\media_entity\MediaInterface $media */