diff --git a/core/modules/media/config/install/core.entity_view_mode.media.full.yml b/core/modules/media/config/install/core.entity_view_mode.media.full.yml new file mode 100644 index 0000000000..dfdbb3a7d6 --- /dev/null +++ b/core/modules/media/config/install/core.entity_view_mode.media.full.yml @@ -0,0 +1,9 @@ +langcode: en +status: false +dependencies: + module: + - media +id: media.full +label: 'Full content' +targetEntityType: media +cache: true diff --git a/core/modules/media/media.module b/core/modules/media/media.module index 2b37b68eea..eeb2ac168a 100644 --- a/core/modules/media/media.module +++ b/core/modules/media/media.module @@ -102,7 +102,7 @@ function media_theme_suggestions_media(array $variables) { * - elements: An array of elements to display in view mode. * - media: The media item. * - name: The label for the media item. - * - view_mode: View mode; e.g. 'teaser'. + * - view_mode: View mode; e.g., 'full', 'teaser', etc. */ function template_preprocess_media(array &$variables) { $variables['media'] = $variables['elements']['#media']; diff --git a/core/modules/media/src/MediaAccessControlHandler.php b/core/modules/media/src/MediaAccessControlHandler.php index 819e68dafe..f753e7fdb2 100644 --- a/core/modules/media/src/MediaAccessControlHandler.php +++ b/core/modules/media/src/MediaAccessControlHandler.php @@ -54,10 +54,7 @@ protected function checkAccess(EntityInterface $entity, $operation, AccountInter * {@inheritdoc} */ protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) { - if ($account->hasPermission('administer media')) { - return AccessResult::allowed()->cachePerPermissions(); - } - return AccessResult::allowedIfHasPermission($account, 'create media'); + return AccessResult::allowedIfHasPermissions($account, ['administer media', 'create media'], 'OR'); } } diff --git a/core/modules/media/templates/media.html.twig b/core/modules/media/templates/media.html.twig index 161f57869d..bff3545be3 100644 --- a/core/modules/media/templates/media.html.twig +++ b/core/modules/media/templates/media.html.twig @@ -21,7 +21,7 @@ * 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". + * - 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. @@ -35,8 +35,12 @@ */ #} + {# + 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 %} + {% if label and view_mode != 'full' %} {{ label }} diff --git a/core/modules/media/tests/src/Functional/MediaTemplateSuggestionsTest.php b/core/modules/media/tests/src/Functional/MediaTemplateSuggestionsTest.php index f29626545a..e0e5294122 100644 --- a/core/modules/media/tests/src/Functional/MediaTemplateSuggestionsTest.php +++ b/core/modules/media/tests/src/Functional/MediaTemplateSuggestionsTest.php @@ -33,14 +33,14 @@ public function testMediaThemeHookSuggestions() { 'name' => 'Unnamed', ]); $media->save(); - $view_mode = 'teaser'; + $view_mode = 'full'; // Simulate theming of the media item. $build = \Drupal::entityTypeManager()->getViewBuilder('media')->view($media, $view_mode); $variables['elements'] = $build; $suggestions = \Drupal::moduleHandler()->invokeAll('theme_suggestions_media', [$variables]); - $this->assertEquals($suggestions, ['media__teaser', 'media__' . $media_type->id(), 'media__' . $media_type->id() . '__teaser'], 'Found expected media suggestions.'); + $this->assertEquals($suggestions, ['media__full', 'media__' . $media_type->id(), 'media__' . $media_type->id() . '__full'], 'Found expected media suggestions.'); } } diff --git a/core/modules/media/tests/src/Kernel/MediaSourceTest.php b/core/modules/media/tests/src/Kernel/MediaSourceTest.php index 60065bf26a..058ffad878 100644 --- a/core/modules/media/tests/src/Kernel/MediaSourceTest.php +++ b/core/modules/media/tests/src/Kernel/MediaSourceTest.php @@ -278,22 +278,14 @@ public function testConstraints() { 'MediaTestConstraint' => [], ]); - // Create media that uses source plugin with constraints and make sure it - // can't be saved without validating them. + // Create a media item media that uses a source plugin with constraints and + // make sure the constraints works as expected when validating. /** @var \Drupal\media\MediaInterface $media */ $media = Media::create([ 'bundle' => $this->testConstraintsMediaType->id(), 'name' => 'I do not like Drupal', 'field_media_test_constraints' => 'Not checked', ]); - try { - $media->save(); - $this->fail('Save was allowed without validation.'); - } - catch (EntityStorageException $exception) { - $this->assertEquals('Entity validation was skipped.', $exception->getMessage(), 'Incorrect validation message.'); - $this->assertTrue(TRUE, 'Validation was enforced before save.'); - } // Validate the entity and make sure violation is reported. /** @var \Drupal\Core\Entity\EntityConstraintViolationListInterface $violations */ @@ -325,14 +317,6 @@ public function testConstraints() { 'name' => 'Not checked', 'field_media_test_constraints' => 'I do not like Drupal', ]); - try { - $media->save(); - $this->fail('Save was allowed without validation.'); - } - catch (EntityStorageException $exception) { - $this->assertEquals('Entity validation was skipped.', $exception->getMessage(), 'Incorrect validation message.'); - $this->assertTrue(TRUE, 'Validation was enforced before save.'); - } // Validate the entity and make sure violation is reported. /** @var \Drupal\Core\Entity\EntityConstraintViolationListInterface $violations */