diff --git a/core/modules/media_entity/media_entity.theme.inc b/core/modules/media_entity/media_entity.theme.inc index c4d1fcb..1efeee6 100644 --- a/core/modules/media_entity/media_entity.theme.inc +++ b/core/modules/media_entity/media_entity.theme.inc @@ -19,10 +19,10 @@ * - media: An individual media for display. */ function template_preprocess_media(array &$variables) { - /** @var \Drupal\media_entity\MediaInterface $media */ - $media = $variables['elements']['#media']; + $variables['media'] = $variables['elements']['#media']; - $variables['name'] = $media->label(); + $variables['view_mode'] = $variables['elements']['#view_mode']; + $variables['name'] = $variables['media']->label(); // Helpful $content variable for templates. foreach (Element::children($variables['elements']) as $key) { @@ -30,11 +30,9 @@ function template_preprocess_media(array &$variables) { } $variables['attributes']['class'][] = 'media'; - $variables['attributes']['class'][] = Html::getClass('media-' . $media->bundle()); - if (!$media->isPublished()) { + $variables['attributes']['class'][] = Html::getClass('media-' . $variables['media']->bundle()); + $variables['attributes']['class'][] = Html::getClass('view-mode-' . $variables['elements']['#view_mode']); + if (!$variables['media']->isPublished()) { $variables['attributes']['class'][] = 'unpublished'; } - if ($variables['elements']['#view_mode']) { - $variables['attributes']['class'][] = Html::getClass('view-mode-' . $variables['elements']['#view_mode']); - } } diff --git a/core/modules/media_entity/src/EmbedCodeValueTrait.php b/core/modules/media_entity/src/EmbedCodeValueTrait.php deleted file mode 100644 index 0694096..0000000 --- a/core/modules/media_entity/src/EmbedCodeValueTrait.php +++ /dev/null @@ -1,35 +0,0 @@ -getFieldDefinition()->getFieldStorageDefinition()->getMainPropertyName(); - if ($property) { - return $value->$property; - } - } - } - -} diff --git a/core/modules/media_entity/src/Entity/Media.php b/core/modules/media_entity/src/Entity/Media.php index 4bada42..42d93c0 100644 --- a/core/modules/media_entity/src/Entity/Media.php +++ b/core/modules/media_entity/src/Entity/Media.php @@ -153,12 +153,6 @@ public function getType() { public function preSave(EntityStorageInterface $storage) { parent::preSave($storage); - // If no revision author has been set explicitly, make the media owner the - // revision author. - if (!$this->get('revision_uid')->entity) { - $this->setRevisionUserId($this->getOwnerId()); - } - // Try to set fields provided by type plugin and mapped in bundle // configuration. foreach ($this->bundle->entity->getFieldMap() as $source_field => $destination_field) { @@ -199,7 +193,8 @@ public function automaticallySetThumbnail() { /** @var \Drupal\Core\Entity\EntityStorageInterface $file_storage */ $file_storage = $this->entityTypeManager()->getStorage('file'); - // If thumbnails should be queued then use default thumbnail, else fetch it. + // If thumbnail fetching should be queued then temporary use default + // thumbnail or fetch it immediately otherwise. if ($this->bundle->entity->getQueueThumbnailDownloads() && $this->isNew()) { $thumbnail_uri = $this->getType()->getDefaultThumbnail(); } @@ -242,6 +237,10 @@ public function preSaveRevision(EntityStorageInterface $storage, \stdClass $reco // entry with an empty one. $record->revision_log = $this->original->revision_log->value; } + + if ($this->isNewRevision()) { + $record->revision_timestamp = \Drupal::time()->getRequestTime(); + } } /** @@ -350,6 +349,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { $fields['revision_uid'] = BaseFieldDefinition::create('entity_reference') ->setLabel(t('Revision publisher ID')) ->setDescription(t('The user ID of the publisher of the current revision.')) + ->setDefaultValueCallback('Drupal\media_entity\Entity\Media::getCurrentUserId') ->setSetting('target_type', 'user') ->setQueryable(FALSE) ->setRevisionable(TRUE); diff --git a/core/modules/media_entity/src/MediaBundleForm.php b/core/modules/media_entity/src/MediaBundleForm.php index 19abedd..6ecad54 100644 --- a/core/modules/media_entity/src/MediaBundleForm.php +++ b/core/modules/media_entity/src/MediaBundleForm.php @@ -9,6 +9,7 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\language\Entity\ContentLanguageSettings; +use Drupal\media_entity\Entity\MediaBundle; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -113,7 +114,7 @@ public function form(array $form, FormStateInterface $form_state) { '#maxlength' => 32, '#disabled' => !$bundle->isNew(), '#machine_name' => [ - 'exists' => ['\Drupal\media_entity\Entity\MediaBundle', 'exists'], + 'exists' => [MediaBundle::class, 'exists'], 'source' => ['label'], ], '#description' => $this->t('A unique machine-readable name for this media bundle.'), diff --git a/core/modules/media_entity/src/MediaForm.php b/core/modules/media_entity/src/MediaForm.php index c917bc6..6d77f99 100644 --- a/core/modules/media_entity/src/MediaForm.php +++ b/core/modules/media_entity/src/MediaForm.php @@ -218,6 +218,7 @@ 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(\Drupal::currentUser()->id()); } $insert = $this->entity->isNew(); @@ -235,8 +236,6 @@ public function save(array $form, FormStateInterface $form_state) { drupal_set_message($this->t('@type %info has been updated.', $t_args)); } - $form_state->setValue('id', $this->entity->id()); - $form_state->set('id', $this->entity->id()); $form_state->setRedirectUrl($this->entity->toUrl('canonical')); } diff --git a/core/modules/media_entity/src/MediaTypeBase.php b/core/modules/media_entity/src/MediaTypeBase.php index 68b1940..26a4830 100644 --- a/core/modules/media_entity/src/MediaTypeBase.php +++ b/core/modules/media_entity/src/MediaTypeBase.php @@ -111,7 +111,7 @@ public function defaultConfiguration() { * {@inheritdoc} */ public function getDefaultThumbnail() { - return ''; + return $this->configFactory->get('media_entity.settings')->get('icon_base') . '/generic.png'; } /** diff --git a/core/modules/media_entity/src/MediaTypeException.php b/core/modules/media_entity/src/MediaTypeException.php deleted file mode 100644 index 9e3ac2c..0000000 --- a/core/modules/media_entity/src/MediaTypeException.php +++ /dev/null @@ -1,45 +0,0 @@ -element = $element; - } - - /** - * Gets element. - * - * @return string - * Element name. - */ - public function getElement() { - return $this->element; - } - -} diff --git a/core/modules/media_entity/src/Plugin/Action/PublishMedia.php b/core/modules/media_entity/src/Plugin/Action/PublishMedia.php index ca758e9..fcea6c3 100644 --- a/core/modules/media_entity/src/Plugin/Action/PublishMedia.php +++ b/core/modules/media_entity/src/Plugin/Action/PublishMedia.php @@ -30,7 +30,7 @@ public function execute(Media $entity = NULL) { public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) { /** @var \Drupal\media_entity\MediaInterface $object */ $result = $object->access('update', $account, TRUE) - ->andIf($object->status->access('edit', $account, TRUE)); + ->andIf($object->status->access('update', $account, TRUE)); return $return_as_object ? $result : $result->isAllowed(); } diff --git a/core/modules/media_entity/src/Plugin/Action/UnpublishMedia.php b/core/modules/media_entity/src/Plugin/Action/UnpublishMedia.php index 14585d5..eb9821f 100644 --- a/core/modules/media_entity/src/Plugin/Action/UnpublishMedia.php +++ b/core/modules/media_entity/src/Plugin/Action/UnpublishMedia.php @@ -30,7 +30,7 @@ public function execute(Media $entity = NULL) { public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) { /** @var \Drupal\media_entity\MediaInterface $object */ $result = $object->access('update', $account, TRUE) - ->andIf($object->status->access('edit', $account, TRUE)); + ->andIf($object->status->access('update', $account, TRUE)); return $return_as_object ? $result : $result->isAllowed(); } diff --git a/core/modules/media_entity/src/Plugin/MediaEntity/Type/Generic.php b/core/modules/media_entity/src/Plugin/MediaEntity/Type/Generic.php index 3a3b40c..021fac6 100644 --- a/core/modules/media_entity/src/Plugin/MediaEntity/Type/Generic.php +++ b/core/modules/media_entity/src/Plugin/MediaEntity/Type/Generic.php @@ -35,19 +35,7 @@ public function getField(MediaInterface $media, $name) { * {@inheritdoc} */ public function thumbnail(MediaInterface $media) { - return $this->configFactory->get('media_entity.settings')->get('icon_base') . '/generic.png'; - } - - /** - * {@inheritdoc} - */ - public function buildConfigurationForm(array $form, FormStateInterface $form_state) { - $form['text'] = [ - '#type' => 'markup', - '#markup' => $this->t("This type provider doesn't need configuration."), - ]; - - return $form; + return $this->getDefaultThumbnail(); } } diff --git a/core/modules/media_entity/templates/media.html.twig b/core/modules/media_entity/templates/media.html.twig index 9d43771..adbc176 100644 --- a/core/modules/media_entity/templates/media.html.twig +++ b/core/modules/media_entity/templates/media.html.twig @@ -4,8 +4,25 @@ * Default theme implementation to present a media entity. * * Available variables: + * - media: The entity with limited access to object properties and methods. + * Only method names starting with "get", "has", or "is" and a few common + * methods such as "id", "label", and "bundle" are available. For example: + * - entity.getEntityTypeId() will return the entity type ID. + * - entity.hasField('field_example') returns TRUE if the entity includes + * field_example. (This does not indicate the presence of a value in this + * field.) + * Calling other methods, such as entity.delete(), will result in an exception. + * See \Drupal\Core\Entity\EntityInterface for a full list of methods. * - name: Name of the media. * - content: Media content. + * - title_prefix: Additional output populated by modules, intended to be + * displayed in front of the main title tag that appears in the template. + * - title_suffix: Additional output populated by modules, intended to be + * displayed after the main title tag that appears in the template. + * - view_mode: View mode; for example, "teaser" or "full". + * - attributes: HTML attributes for the containing element. + * - title_attributes: Same as attributes, except applied to the main title + * tag that appears in the template. * * @see template_preprocess_media() * @@ -13,6 +30,18 @@ */ #} + {# + In the 'full' view mode the entity label is assumed to be displayed as the + page title, so we do not display it here. + #} + {{ title_prefix }} + {% if label and view_mode != 'full' %} + + {{ label }} + + {% endif %} + {{ title_suffix }} + {% if content %} {{ content }} {% endif %} diff --git a/core/modules/media_entity/tests/src/FunctionalJavascript/MediaUiJavascriptTest.php b/core/modules/media_entity/tests/src/FunctionalJavascript/MediaUiJavascriptTest.php index 463f620..6711181 100644 --- a/core/modules/media_entity/tests/src/FunctionalJavascript/MediaUiJavascriptTest.php +++ b/core/modules/media_entity/tests/src/FunctionalJavascript/MediaUiJavascriptTest.php @@ -85,7 +85,6 @@ public function testMediaBundles() { $assert_session->pageTextContains('Automatically create a new revision of media entities. Users with the Administer media permission will be able to override this option.'); $assert_session->pageTextContains('Download thumbnails via a queue.'); $assert_session->pageTextContains('Entities will be automatically published when they are created.'); - $assert_session->pageTextContains("This type provider doesn't need configuration."); $assert_session->pageTextContains('No metadata fields available.'); $assert_session->pageTextContains('Media type plugins can provide metadata fields such as title, caption, size information, credits, ... Media entity can automatically save this metadata information to entity fields, which can be configured below. Information will only be mapped if the entity field is empty.');