diff --git a/core/modules/media/media.install b/core/modules/media/media.install index eda4cce..d26b1cd 100644 --- a/core/modules/media/media.install +++ b/core/modules/media/media.install @@ -123,11 +123,16 @@ function media_requirements($phase) { if (!empty($types_to_warn)) { $requirements['media_private_scheme_in_use'] = [ 'title' => t('Media'), - 'description' => t('The private file storage was configured for the source field(s) on Media type(s): %types. By default, access control for assets on media items is not inherited from the entity that references them. More information about how to restrict access for assets on media items can be found on this documentation page.', [ - '%types' => implode(", ", $types_to_warn), - '@doc_url' => 'https://www.drupal.org/docs/8/core/modules/media/setting-up-private-access-to-media-items', - ]), - 'severity' => REQUIREMENT_WARNING, + 'description' => \Drupal::translation()->formatPlural( + count($types_to_warn), + 'Media type %type uses the private file storage. By default, the media items will be accessible to any users with access to %type media, even if the user does not have access to content that references it. More information on configuring media access restrictions.', + 'Media types %types use the private file storage. By default, the media items will be accessible to any users with access to %types media, even if the user does not have access to content that references them. More information on configuring media access restrictions.', + [ + '%type' => reset($types_to_warn), + '%types' => implode(", ", $types_to_warn), + '@doc_url' => 'https://www.drupal.org/docs/8/core/modules/media/setting-up-private-access-to-media-items', + ]), + 'severity' => REQUIREMENT_INFO, ]; } } diff --git a/core/modules/media/media.module b/core/modules/media/media.module index 9cecdf5..ad1985f 100644 --- a/core/modules/media/media.module +++ b/core/modules/media/media.module @@ -58,7 +58,30 @@ function media_help($route_name, RouteMatchInterface $route_match) { $output .= '
' . t('Use Media reference fields for most files, images, audio, videos, and remote media. Use File or Image reference fields when creating your own media types, or for legacy files and images created before enabling the Media module.') . '
'; + $output .= '' . t('Media items behave differently than files and images regarding restricted access. While files and images, when configured to use the private storage, will inherit access permissions from the content where they are attached to, Media items have their own access restrictions. This usually means that by default users could have access to files on Media items even though they do not have access to the content that references the Media items. More information on configuring media access restrictions.', [ + '@doc_url' => 'https://www.drupal.org/docs/8/core/modules/media/setting-up-private-access-to-media-items', + ]) . '
'; return $output; + + case 'entity.media.field_ui_fields': + // If there are file fields on media types using the private scheme, users + // may have the expectation that they inherit access from their parent + // entities, which is something that media items don't do by default. + // Show a message letting them know that. + $media_type = \Drupal::routeMatch()->getParameter('media_type'); + /** @var \Drupal\field\FieldConfigInterface $source_definition */ + $source_definition = $media_type->getSource()->getSourceFieldDefinition($media_type); + if (!in_array($source_definition->getType(), ['file', 'image'])) { + return; + } + if ($source_definition->getSetting('uri_scheme') === 'private' + && \Drupal::config('media.settings')->get('show_private_scheme_warning')) { + return '' . t('The source field is configured to use the private file storage. By default, the media items will be accessible to any users with access to %type media, even if the user does not have access to content that references it. More information on configuring media access restrictions.', [ + '%type' => $media_type->label(), + '@doc_url' => 'https://www.drupal.org/docs/8/core/modules/media/setting-up-private-access-to-media-items', + ]) . '
'; + } } } @@ -336,28 +359,3 @@ function media_preprocess_media_reference_help(&$variables) { } } } - -/** - * Implements hook_page_attachments(). - */ -function media_page_attachments(&$attachments) { - // If there are file fields on media types using the private scheme, users - // may have the expectation that they inherit access from their parent - // entities, which is something that media items don't do by default. Show a - // warning letting users know that. - if (\Drupal::routeMatch()->getRouteName() !== 'entity.media.field_ui_fields') { - return; - } - $media_type = \Drupal::routeMatch()->getParameter('media_type'); - /** @var \Drupal\field\FieldConfigInterface $source_definition */ - $source_definition = $media_type->getSource()->getSourceFieldDefinition($media_type); - if (!in_array($source_definition->getType(), ['file', 'image'])) { - return; - } - if ($source_definition->getSetting('uri_scheme') === 'private' - && \Drupal::config('media.settings')->get('show_private_scheme_warning')) { - \Drupal::messenger()->addWarning(t('The source field is configured to use the private file storage. By default, access control for assets on media items is not inherited from the entity that references them. More information about how to restrict access for assets on media items can be found on this documentation page.', [ - '@doc_url' => 'https://www.drupal.org/docs/8/core/modules/media/setting-up-private-access-to-media-items', - ])); - } -}