media.module 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  1. <?php
  2. /**
  3. * @file
  4. * Provides media items.
  5. */
  6. use Drupal\Component\Plugin\DerivativeInspectionInterface;
  7. use Drupal\Core\Access\AccessResult;
  8. use Drupal\Core\Entity\EntityInterface;
  9. use Drupal\Core\Form\FormStateInterface;
  10. use Drupal\Core\Render\Element;
  11. use Drupal\Core\Render\Element\RenderElement;
  12. use Drupal\Core\Routing\RouteMatchInterface;
  13. use Drupal\Core\Session\AccountInterface;
  14. use Drupal\Core\Template\Attribute;
  15. use Drupal\Core\Url;
  16. use Drupal\field\FieldConfigInterface;
  17. use Drupal\media\Plugin\media\Source\OEmbedInterface;
  18. use Drupal\views\ViewExecutable;
  19. /**
  20. * Implements hook_help().
  21. */
  22. function media_help($route_name, RouteMatchInterface $route_match) {
  23. switch ($route_name) {
  24. case 'help.page.media':
  25. $output = '<h3>' . t('About') . '</h3>';
  26. $output .= '<p>' . 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 <a href=":media">online documentation for the Media module</a>.', [':media' => 'https://www.drupal.org/docs/8/core/modules/media']) . '</p>';
  27. $output .= '<h3>' . t('Uses') . '</h3>';
  28. $output .= '<dl>';
  29. $output .= '<dt>' . t('Creating media items') . '</dt>';
  30. $output .= '<dd>' . t('When a new media item is created, the Media module records basic information about it, including the author, date of creation, and the <a href=":media-type">media type</a>. It also manages the <em>publishing options</em>, 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()]) . '</dd>';
  31. $output .= '<dt>' . t('Listing media items') . '</dt>';
  32. $output .= '<dd>' . t('Media items are listed at the <a href=":media-collection">media administration page</a>.', [
  33. ':media-collection' => Url::fromRoute('entity.media.collection')->toString(),
  34. ]) . '</dd>';
  35. $output .= '<dt>' . t('Creating custom media types') . '</dt>';
  36. $output .= '<dd>' . t('The Media module gives users with the <em>Administer media types</em> permission the ability to <a href=":media-new">create new media types</a> 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 <a href=":field">Field module</a> may be added for storing that metadata, such as width and height, as well as any other associated values.', [
  37. ':media-new' => Url::fromRoute('entity.media_type.add_form')->toString(),
  38. ':field' => Url::fromRoute('help.page', ['name' => 'field'])->toString(),
  39. ]) . '</dd>';
  40. $output .= '<dt>' . t('Creating revisions') . '</dt>';
  41. $output .= '<dd>' . t('The Media module also enables you to create multiple versions of any media item, and revert to older versions using the <em>Revision information</em> settings.') . '</dd>';
  42. $output .= '<dt>' . t('User permissions') . '</dt>';
  43. $output .= '<dd>' . t('The Media module makes a number of permissions available, which can be set by role on the <a href=":permissions">permissions page</a>.', [
  44. ':permissions' => Url::fromRoute('user.admin_permissions', [], ['fragment' => 'module-media'])->toString(),
  45. ]) . '</dd>';
  46. $output .= '<dt>' . t('Adding media to other content') . '</dt>';
  47. $output .= '<dd>' . t('Users with permission to administer content types can add media support by adding a media reference field to the content type on the content type administration page. (The same is true of block types, taxonomy terms, user profiles, and other content that supports fields.) A media reference field can refer to any configured media type. It is possible to allow multiple media types in the same field.') . '</dd>';
  48. $output .= '</dl>';
  49. $output .= '<h3>' . t('Differences between Media, File, and Image reference fields') . '</h3>';
  50. $output .= '<p>' . t('<em>Media</em> reference fields offer several advantages over basic <em>File</em> and <em>Image</em> references:') . '</p>';
  51. $output .= '<ul>';
  52. $output .= '<li>' . t('Media reference fields can reference multiple media types in the same field.') . '</li>';
  53. $output .= '<li>' . t('Fields can also be added to media types themselves, which means that custom metadata like descriptions and taxonomy tags can be added for the referenced media. (Basic file and image fields do not support this.)') . '</li>';
  54. $output .= '<li>' . t('Media types for audio and video files are provided by default, so there is no need for additional configuration to upload these media.') . '</li>';
  55. $output .= '<li>' . t('Contributed or custom projects can provide additional media sources (such as third-party websites, Twitter, etc.).') . '</li>';
  56. $output .= '<li>' . t('Existing media items can be reused on any other content items with a media reference field.') . '</li>';
  57. $output .= '</ul>';
  58. $output .= '<p>' . t('Use <em>Media</em> reference fields for most files, images, audio, videos, and remote media. Use <em>File</em> or <em>Image</em> reference fields when creating your own media types, or for legacy files and images created before enabling the Media module.') . '</p>';
  59. return $output;
  60. }
  61. }
  62. /**
  63. * Implements hook_theme().
  64. */
  65. function media_theme() {
  66. return [
  67. 'media' => [
  68. 'render element' => 'elements',
  69. ],
  70. 'media_reference_help' => [
  71. 'render element' => 'element',
  72. 'base hook' => 'field_multiple_value_form',
  73. ],
  74. 'media_oembed_iframe' => [
  75. 'variables' => [
  76. 'media' => NULL,
  77. 'placeholder_token' => '',
  78. ],
  79. ],
  80. 'media_embed_error' => [
  81. 'variables' => [
  82. 'message' => NULL,
  83. 'attributes' => [],
  84. ],
  85. ],
  86. ];
  87. }
  88. /**
  89. * Implements hook_entity_access().
  90. */
  91. function media_entity_access(EntityInterface $entity, $operation, AccountInterface $account) {
  92. if ($operation === 'delete' && $entity instanceof FieldConfigInterface && $entity->getTargetEntityTypeId() === 'media') {
  93. /** @var \Drupal\media\MediaTypeInterface $media_type */
  94. $media_type = \Drupal::entityTypeManager()->getStorage('media_type')->load($entity->getTargetBundle());
  95. return AccessResult::forbiddenIf($entity->id() === 'media.' . $media_type->id() . '.' . $media_type->getSource()->getConfiguration()['source_field']);
  96. }
  97. return AccessResult::neutral();
  98. }
  99. /**
  100. * Implements hook_theme_suggestions_HOOK().
  101. */
  102. function media_theme_suggestions_media(array $variables) {
  103. $suggestions = [];
  104. /** @var \Drupal\media\MediaInterface $media */
  105. $media = $variables['elements']['#media'];
  106. $sanitized_view_mode = strtr($variables['elements']['#view_mode'], '.', '_');
  107. $suggestions[] = 'media__' . $sanitized_view_mode;
  108. $suggestions[] = 'media__' . $media->bundle();
  109. $suggestions[] = 'media__' . $media->bundle() . '__' . $sanitized_view_mode;
  110. // Add suggestions based on the source plugin ID.
  111. $source = $media->getSource();
  112. if ($source instanceof DerivativeInspectionInterface) {
  113. $source_id = $source->getBaseId();
  114. $derivative_id = $source->getDerivativeId();
  115. if ($derivative_id) {
  116. $source_id .= '__derivative_' . $derivative_id;
  117. }
  118. }
  119. else {
  120. $source_id = $source->getPluginId();
  121. }
  122. $suggestions[] = "media__source_$source_id";
  123. // If the source plugin uses oEmbed, add a suggestion based on the provider
  124. // name, if available.
  125. if ($source instanceof OEmbedInterface) {
  126. $provider_id = $source->getMetadata($media, 'provider_name');
  127. if ($provider_id) {
  128. $provider_id = \Drupal::transliteration()->transliterate($provider_id);
  129. $provider_id = preg_replace('/[^a-z0-9_]+/', '_', mb_strtolower($provider_id));
  130. $suggestions[] = end($suggestions) . "__provider_$provider_id";
  131. }
  132. }
  133. return $suggestions;
  134. }
  135. /**
  136. * Prepares variables for media templates.
  137. *
  138. * Default template: media.html.twig.
  139. *
  140. * @param array $variables
  141. * An associative array containing:
  142. * - elements: An array of elements to display in view mode.
  143. * - media: The media item.
  144. * - name: The label for the media item.
  145. * - view_mode: View mode; e.g., 'full', 'teaser', etc.
  146. */
  147. function template_preprocess_media(array &$variables) {
  148. $variables['media'] = $variables['elements']['#media'];
  149. $variables['view_mode'] = $variables['elements']['#view_mode'];
  150. $variables['name'] = $variables['media']->label();
  151. // Helpful $content variable for templates.
  152. foreach (Element::children($variables['elements']) as $key) {
  153. $variables['content'][$key] = $variables['elements'][$key];
  154. }
  155. }
  156. /**
  157. * Implements hook_field_ui_preconfigured_options_alter().
  158. */
  159. function media_field_ui_preconfigured_options_alter(array &$options, $field_type) {
  160. // If the field is not an "entity_reference"-based field, bail out.
  161. /** @var \Drupal\Core\Field\FieldTypePluginManager $field_type_manager */
  162. $field_type_manager = \Drupal::service('plugin.manager.field.field_type');
  163. $class = $field_type_manager->getPluginClass($field_type);
  164. if (!is_a($class, 'Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem', TRUE)) {
  165. return;
  166. }
  167. // Set the default formatter for media in entity reference fields to be the
  168. // "Rendered entity" formatter.
  169. if (!empty($options['media'])) {
  170. $options['media']['entity_view_display']['type'] = 'entity_reference_entity_view';
  171. }
  172. }
  173. /**
  174. * Implements hook_form_FORM_ID_alter().
  175. */
  176. function media_form_field_ui_field_storage_add_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  177. // Provide some help text to aid users decide whether they need a Media,
  178. // File, or Image reference field.
  179. $description_text = t('Use <em>Media</em> reference fields for most files, images, audio, videos, and remote media. Use <em>File</em> or <em>Image</em> reference fields when creating your own media types, or for legacy files and images created before enabling the Media module.');
  180. if (\Drupal::moduleHandler()->moduleExists('help')) {
  181. $description_text .= ' ' . t('For more information, see the <a href="@help_url">Media help page</a>.', [
  182. '@help_url' => Url::fromRoute('help.page', ['name' => 'media'])->toString(),
  183. ]);
  184. }
  185. $form['add']['description_wrapper'] = [
  186. '#type' => 'container',
  187. ];
  188. $field_types = [
  189. 'file',
  190. 'image',
  191. 'field_ui:entity_reference:media',
  192. ];
  193. foreach ($field_types as $field_name) {
  194. $form['add']['description_wrapper']["description_{$field_name}"] = [
  195. '#type' => 'item',
  196. '#markup' => $description_text,
  197. '#states' => [
  198. 'visible' => [
  199. ':input[name="new_storage_type"]' => ['value' => $field_name],
  200. ],
  201. ],
  202. ];
  203. }
  204. $form['add']['new_storage_type']['#weight'] = 0;
  205. $form['add']['description_wrapper']['#weight'] = 1;
  206. }
  207. /**
  208. * Implements hook_field_widget_multivalue_form_alter().
  209. */
  210. function media_field_widget_multivalue_form_alter(array &$elements, FormStateInterface $form_state, array $context) {
  211. // Do not alter the default settings form.
  212. if ($context['default']) {
  213. return;
  214. }
  215. // Only act on entity reference fields that reference media.
  216. $field_type = $context['items']->getFieldDefinition()->getType();
  217. $target_type = $context['items']->getFieldDefinition()->getFieldStorageDefinition()->getSetting('target_type');
  218. if ($field_type !== 'entity_reference' || $target_type !== 'media') {
  219. return;
  220. }
  221. // Autocomplete widgets need different help text than options widgets.
  222. $widget_plugin_id = $context['widget']->getPluginId();
  223. if (in_array($widget_plugin_id, ['entity_reference_autocomplete', 'entity_reference_autocomplete_tags'])) {
  224. $is_autocomplete = TRUE;
  225. }
  226. else {
  227. // @todo We can't yet properly alter non-autocomplete fields. Resolve this
  228. // in https://www.drupal.org/node/2943020 and remove this condition.
  229. return;
  230. }
  231. $elements['#media_help'] = [];
  232. // Retrieve the media bundle list and add information for the user based on
  233. // which bundles are available to be created or referenced.
  234. $settings = $context['items']->getFieldDefinition()->getSetting('handler_settings');
  235. $allowed_bundles = !empty($settings['target_bundles']) ? $settings['target_bundles'] : [];
  236. $add_url = _media_get_add_url($allowed_bundles);
  237. if ($add_url) {
  238. $elements['#media_help']['#media_add_help'] = t('Create your media on the <a href=":add_page" target="_blank">media add page</a> (opens a new window), then add it by name to the field below.', [':add_page' => $add_url]);
  239. }
  240. $elements['#theme'] = 'media_reference_help';
  241. // @todo template_preprocess_field_multiple_value_form() assumes this key
  242. // exists, but it does not exist in the case of a single widget that
  243. // accepts multiple values. This is for some reason necessary to use
  244. // our template for the entity_autocomplete_tags widget.
  245. // Research and resolve this in https://www.drupal.org/node/2943020.
  246. if (empty($elements['#cardinality_multiple'])) {
  247. $elements['#cardinality_multiple'] = NULL;
  248. }
  249. // Use the title set on the element if it exists, otherwise fall back to the
  250. // field label.
  251. $elements['#media_help']['#original_label'] = isset($elements['#title']) ? $elements['#title'] : $context['items']->getFieldDefinition()->getLabel();
  252. // Customize the label for the field widget.
  253. // @todo Research a better approach https://www.drupal.org/node/2943024.
  254. $use_existing_label = t('Use existing media');
  255. if (!empty($elements[0]['target_id']['#title'])) {
  256. $elements[0]['target_id']['#title'] = $use_existing_label;
  257. }
  258. if (!empty($elements['#title'])) {
  259. $elements['#title'] = $use_existing_label;
  260. }
  261. if (!empty($elements['target_id']['#title'])) {
  262. $elements['target_id']['#title'] = $use_existing_label;
  263. }
  264. // This help text is only relevant for autocomplete widgets. When the user
  265. // is presented with options, they don't need to type anything or know what
  266. // types of media are allowed.
  267. if ($is_autocomplete) {
  268. $elements['#media_help']['#media_list_help'] = t('Type part of the media name.');
  269. $overview_url = Url::fromRoute('entity.media.collection');
  270. if ($overview_url->access()) {
  271. $elements['#media_help']['#media_list_link'] = t('See the <a href=":list_url" target="_blank">media list</a> (opens a new window) to help locate media.', [':list_url' => $overview_url->toString()]);
  272. }
  273. $all_bundles = \Drupal::service('entity_type.bundle.info')->getBundleInfo('media');
  274. $bundle_labels = array_map(function ($bundle) use ($all_bundles) {
  275. return $all_bundles[$bundle]['label'];
  276. }, $allowed_bundles);
  277. $elements['#media_help']['#allowed_types_help'] = t('Allowed media types: %types', ['%types' => implode(", ", $bundle_labels)]);
  278. }
  279. }
  280. /**
  281. * Implements hook_preprocess_HOOK() for media reference widgets.
  282. */
  283. function media_preprocess_media_reference_help(&$variables) {
  284. // Most of these attribute checks are copied from
  285. // template_preprocess_fieldset(). Our template extends
  286. // field-multiple-value-form.html.twig to provide our help text, but also
  287. // groups the information within a semantic fieldset with a legend. So, we
  288. // incorporate parity for both.
  289. $element = $variables['element'];
  290. Element::setAttributes($element, ['id']);
  291. RenderElement::setAttributes($element);
  292. $variables['attributes'] = isset($element['#attributes']) ? $element['#attributes'] : [];
  293. $variables['legend_attributes'] = new Attribute();
  294. $variables['header_attributes'] = new Attribute();
  295. $variables['description']['attributes'] = new Attribute();
  296. $variables['legend_span_attributes'] = new Attribute();
  297. if (!empty($element['#media_help'])) {
  298. foreach ($element['#media_help'] as $key => $text) {
  299. $variables[substr($key, 1)] = $text;
  300. }
  301. }
  302. }
  303. /**
  304. * Returns the appropriate URL to add media for the current user.
  305. *
  306. * @todo Remove in https://www.drupal.org/project/drupal/issues/2938116
  307. *
  308. * @param string[] $allowed_bundles
  309. * An array of bundles that should be checked for create access.
  310. *
  311. * @return bool|\Drupal\Core\Url
  312. * The URL to add media, or FALSE if the user cannot create any media.
  313. *
  314. * @internal
  315. * This function is internal and may be removed in a minor release.
  316. */
  317. function _media_get_add_url($allowed_bundles) {
  318. $access_handler = \Drupal::entityTypeManager()->getAccessControlHandler('media');
  319. $create_bundles = array_filter($allowed_bundles, [$access_handler, 'createAccess']);
  320. // Add a section about how to create media if the user has access to do so.
  321. if (count($create_bundles) === 1) {
  322. return Url::fromRoute('entity.media.add_form', ['media_type' => reset($create_bundles)])->toString();
  323. }
  324. elseif (count($create_bundles) > 1) {
  325. return Url::fromRoute('entity.media.add_page')->toString();
  326. }
  327. return FALSE;
  328. }
  329. /**
  330. * Implements hook_entity_type_alter().
  331. */
  332. function media_entity_type_alter(array &$entity_types) {
  333. if (\Drupal::config('media.settings')->get('standalone_url')) {
  334. /** @var \Drupal\Core\Entity\ContentEntityTypeInterface $entity_type */
  335. $entity_type = $entity_types['media'];
  336. $entity_type->setLinkTemplate('canonical', '/media/{media}');
  337. }
  338. }
  339. /**
  340. * Implements hook_form_FORM_ID_alter().
  341. */
  342. function media_form_filter_format_edit_form_alter(array &$form, FormStateInterface $form_state, $form_id) {
  343. // Add an additional validate callback so we can ensure the order of filters
  344. // is correct.
  345. $form['#validate'][] = 'media_filter_format_edit_form_validate';
  346. }
  347. /**
  348. * Implements hook_form_FORM_ID_alter().
  349. */
  350. function media_form_filter_format_add_form_alter(array &$form, FormStateInterface $form_state, $form_id) {
  351. // Add an additional validate callback so we can ensure the order of filters
  352. // is correct.
  353. $form['#validate'][] = 'media_filter_format_edit_form_validate';
  354. }
  355. /**
  356. * Validate callback to ensure filter order and allowed_html are compatible.
  357. */
  358. function media_filter_format_edit_form_validate($form, FormStateInterface $form_state) {
  359. if ($form_state->getTriggeringElement()['#name'] !== 'op') {
  360. return;
  361. }
  362. $allowed_html_path = [
  363. 'filters',
  364. 'filter_html',
  365. 'settings',
  366. 'allowed_html',
  367. ];
  368. $filter_html_settings_path = [
  369. 'filters',
  370. 'filter_html',
  371. 'settings',
  372. ];
  373. $filter_html_enabled = $form_state->getValue([
  374. 'filters',
  375. 'filter_html',
  376. 'status',
  377. ]);
  378. $media_embed_enabled = $form_state->getValue([
  379. 'filters',
  380. 'media_embed',
  381. 'status',
  382. ]);
  383. if (!$media_embed_enabled) {
  384. return;
  385. }
  386. $get_filter_label = function ($filter_plugin_id) use ($form) {
  387. return (string) $form['filters']['order'][$filter_plugin_id]['filter']['#markup'];
  388. };
  389. if ($filter_html_enabled && $form_state->getValue($allowed_html_path)) {
  390. /** @var \Drupal\filter\Entity\FilterFormat $filter_format */
  391. $filter_format = $form_state->getFormObject()->getEntity();
  392. $filter_html = clone $filter_format->filters()->get('filter_html');
  393. $filter_html->setConfiguration(['settings' => $form_state->getValue($filter_html_settings_path)]);
  394. $restrictions = $filter_html->getHTMLRestrictions();
  395. $allowed = $restrictions['allowed'];
  396. // Require `<drupal-media>` HTML tag if filter_html is enabled.
  397. if (!isset($allowed['drupal-media'])) {
  398. $form_state->setError($form['filters']['settings']['filter_html']['allowed_html'], t('The %media-embed-filter-label filter requires <code>&lt;drupal-media&gt;</code> among the allowed HTML tags.', [
  399. '%media-embed-filter-label' => $get_filter_label('media_embed'),
  400. ]));
  401. }
  402. else {
  403. $required_attributes = [
  404. 'data-entity-type',
  405. 'data-entity-uuid',
  406. ];
  407. // If there are no attributes, the allowed item is set to FALSE,
  408. // otherwise, it is set to an array.
  409. if ($allowed['drupal-media'] === FALSE) {
  410. $missing_attributes = $required_attributes;
  411. }
  412. else {
  413. $missing_attributes = array_diff($required_attributes, array_keys($allowed['drupal-media']));
  414. }
  415. if ($missing_attributes) {
  416. $form_state->setError($form['filters']['settings']['filter_html']['allowed_html'], t('The <code>&lt;drupal-media&gt;</code> tag in the allowed HTML tags is missing the following attributes: <code>%list</code>.', [
  417. '%list' => implode(', ', $missing_attributes),
  418. ]));
  419. }
  420. }
  421. }
  422. $filters = $form_state->getValue('filters');
  423. // The "media_embed" filter must run after "filter_align", "filter_caption",
  424. // and "filter_html_image_secure".
  425. $precedents = [
  426. 'filter_align',
  427. 'filter_caption',
  428. 'filter_html_image_secure',
  429. ];
  430. $error_filters = [];
  431. foreach ($precedents as $filter_name) {
  432. // A filter that should run before media embed filter.
  433. $precedent = $filters[$filter_name];
  434. if (empty($precedent['status']) || !isset($precedent['weight'])) {
  435. continue;
  436. }
  437. if ($precedent['weight'] >= $filters['media_embed']['weight']) {
  438. $error_filters[$filter_name] = $get_filter_label($filter_name);
  439. }
  440. }
  441. if (!empty($error_filters)) {
  442. $error_message = \Drupal::translation()->formatPlural(
  443. count($error_filters),
  444. 'The %media-embed-filter-label filter needs to be placed after the %filter filter.',
  445. 'The %media-embed-filter-label filter needs to be placed after the following filters: %filters.',
  446. [
  447. '%media-embed-filter-label' => $get_filter_label('media_embed'),
  448. '%filter' => reset($error_filters),
  449. '%filters' => implode(', ', $error_filters),
  450. ]
  451. );
  452. $form_state->setErrorByName('filters', $error_message);
  453. }
  454. }
  455. /**
  456. * Implements hook_field_widget_form_alter().
  457. */
  458. function media_field_widget_form_alter(&$element, FormStateInterface $form_state, $context) {
  459. // Add an attribute so that "drupalmedia" CKEditor plugin can pass the host
  460. // entity's language to EditorMediaDialog, allowing it to present entities
  461. // in the same language.
  462. if (!empty($element['#type']) && $element['#type'] == 'text_format') {
  463. $element['#attributes']['data-media-embed-host-entity-langcode'] = $context['items']->getLangcode();
  464. }
  465. }
  466. /**
  467. * Implements hook_views_query_substitutions().
  468. */
  469. function media_views_query_substitutions(ViewExecutable $view) {
  470. $account = \Drupal::currentUser();
  471. return [
  472. '***VIEW_OWN_UNPUBLISHED_MEDIA***' => (int) $account->hasPermission('view own unpublished media'),
  473. '***ADMINISTER_MEDIA***' => (int) $account->hasPermission('administer media'),
  474. ];
  475. }