' . t('About') . ''; $output .= '

' . t('The Media module manages the creation, editing, deletion, settings and display of media. Items are typically images, documents, slideshows, YouTube videos, tweets, Instagram photos, etc. You can reference media items from any other content on your site. For more information, see the online documentation for the Media module.', [':media' => 'https://www.drupal.org/docs/8/core/modules/media']) . '

'; $output .= '

' . t('Uses') . '

'; $output .= '
'; $output .= '
' . t('Creating media items') . '
'; $output .= '
' . t('When a new media item is created, the Media module records basic information about it, including the author, date of creation, and the media type. It also manages the publishing options, which define whether or not the item is published. Default settings can be configured for each type of media on your site.', [':media-type' => Url::fromRoute('entity.media_type.collection')->toString()]) . '
'; $output .= '
' . t('Creating custom media types') . '
'; $output .= '
' . t('The Media module gives users with the Administer media types permission the ability to create new media types in addition to the default ones already configured. Each media type has an associated media source (such as the image source) which support thumbnail generation and metadata extraction. Fields managed by the Field module may be added for storing that metadata, such as width and height, as well as any other associated values.', [':media-new' => Url::fromRoute('entity.media_type.add_form')->toString(), ':field' => Url::fromRoute('help.page', ['name' => 'field'])->toString()]) . '
'; $output .= '
' . t('Creating revisions') . '
'; $output .= '
' . t('The Media module also enables you to create multiple versions of any media item, and revert to older versions using the Revision information settings.') . '
'; $output .= '
' . t('User permissions') . '
'; $output .= '
' . t('The Media module makes a number of permissions available, which can be set by role on the permissions page.', [':permissions' => Url::fromRoute('user.admin_permissions', [], ['fragment' => 'module-media'])->toString()]) . '
'; $output .= '
'; return $output; } } /** * Implements hook_theme(). */ function media_theme() { return [ 'media' => [ 'render element' => 'elements', ], ]; } /** * Implements hook_entity_operation_alter(). * * Fix broken operations array in field UI for entities with restricted access. * * @todo This hook can be removed when issue #2836384 is done. * @see https://www.drupal.org/node/2836384 */ function media_entity_operation_alter(array &$operations, EntityInterface $entity) { if ($entity instanceof FieldConfigInterface && $entity->getTargetEntityTypeId() === 'media') { /** @var \Drupal\media\MediaTypeInterface $media_type */ $media_type = \Drupal::entityTypeManager()->getStorage('media_type')->load($entity->getTargetBundle()); if ($entity->id() === 'media.' . $media_type->id() . '.' . $media_type->getSource()->getConfiguration()['source_field']) { unset($operations['delete']); } } } /** * Implements hook_entity_access(). */ function media_entity_access(EntityInterface $entity, $operation, AccountInterface $account) { if ($operation === 'delete' && $entity instanceof FieldConfigInterface && $entity->getTargetEntityTypeId() === 'media') { /** @var \Drupal\media\MediaTypeInterface $media_type */ $media_type = \Drupal::entityTypeManager()->getStorage('media_type')->load($entity->getTargetBundle()); return AccessResult::forbiddenIf($entity->id() === 'media.' . $media_type->id() . '.' . $media_type->getSource()->getConfiguration()['source_field']); } return AccessResult::neutral(); } /** * Implements hook_theme_suggestions_HOOK(). */ function media_theme_suggestions_media(array $variables) { $suggestions = []; $media = $variables['elements']['#media']; $sanitized_view_mode = strtr($variables['elements']['#view_mode'], '.', '_'); $suggestions[] = 'media__' . $sanitized_view_mode; $suggestions[] = 'media__' . $media->bundle(); $suggestions[] = 'media__' . $media->bundle() . '__' . $sanitized_view_mode; return $suggestions; } /** * Prepares variables for media templates. * * Default template: media.html.twig. * * @param array $variables * An associative array containing: * - 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., 'full', 'teaser', etc. */ function template_preprocess_media(array &$variables) { $variables['media'] = $variables['elements']['#media']; $variables['view_mode'] = $variables['elements']['#view_mode']; $variables['name'] = $variables['media']->label(); // Helpful $content variable for templates. foreach (Element::children($variables['elements']) as $key) { $variables['content'][$key] = $variables['elements'][$key]; } }