media.module

Same filename and directory in other branches
  1. 10 core/modules/media/media.module
  2. 9 core/modules/media/media.module
  3. 8.9.x core/modules/media/media.module
  4. main core/modules/media/media.module

File

core/modules/media/media.module

View source
<?php


/**
 * @file
 */

use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\media\Hook\MediaHooks;
use Drupal\media\Hook\MediaThemeHooks;

/**
 * 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.
 *
 * @deprecated in drupal:11.3.0 and is removed from drupal:12.0.0. Initial
 *   template_preprocess functions are registered directly in hook_theme().
 *
 * @see https://www.drupal.org/node/3504125
 */
function template_preprocess_media(array &$variables) : void {
  @trigger_error(__FUNCTION__ . '() is deprecated in drupal:11.3.0 and is removed from drupal:12.0.0. Initial template_preprocess functions are registered directly in hook_theme(). See https://www.drupal.org/node/3504125', E_USER_DEPRECATED);
  \Drupal::service(MediaThemeHooks::class)->preprocessMedia($variables);
}

/**
 * Returns the appropriate URL to add media for the current user.
 *
 * @todo Remove in https://www.drupal.org/project/drupal/issues/2938116
 *
 * @param string[] $allowed_bundles
 *   An array of bundles that should be checked for create access.
 *
 * @return bool|\Drupal\Core\Url
 *   The URL to add media, or FALSE if the user cannot create any media.
 *
 * @internal
 *   This function is internal and may be removed in a minor release.
 *
 * @deprecated in drupal:11.4.0 and is removed from drupal:12.0.0. There is no
 *   replacement.
 *
 * @see https://www.drupal.org/node/3566774
 */
function _media_get_add_url($allowed_bundles) {
  @trigger_error(__FUNCTION__ . '() is deprecated in drupal:11.4.0 and is removed from drupal:12.0.0. There is no replacement. See https://www.drupal.org/node/3566774', E_USER_DEPRECATED);
  $access_handler = \Drupal::entityTypeManager()->getAccessControlHandler('media');
  $create_bundles = array_filter($allowed_bundles, [
    $access_handler,
    'createAccess',
  ]);
  // Add a section about how to create media if the user has access to do so.
  if (count($create_bundles) === 1) {
    return Url::fromRoute('entity.media.add_form', [
      'media_type' => reset($create_bundles),
    ])->toString();
  }
  elseif (count($create_bundles) > 1) {
    return Url::fromRoute('entity.media.add_page')->toString();
  }
  return FALSE;
}

/**
 * Validate callback to ensure filter order and allowed_html are compatible.
 *
 * @deprecated in drupal:11.4.0 and is removed from drupal:12.0.0. Use
 *   MediaHooks::formatEditFormValidate() instead.
 *
 * @see https://www.drupal.org/node/3566774
 * @see \Drupal\media\Hook\MediaHooks::formatEditFormValidate()
 */
function media_filter_format_edit_form_validate($form, FormStateInterface $form_state) : void {
  @trigger_error(__FUNCTION__ . '() is deprecated in drupal:11.4.0 and is removed from drupal:12.0.0. Use \\Drupal\\media\\Hook\\MediaHooks::formatEditFormValidate() instead. See https://www.drupal.org/node/3566774', E_USER_DEPRECATED);
  \Drupal::service(MediaHooks::class)->formatEditFormValidate($form, $form_state);
}

Functions

Title Deprecated Summary
media_filter_format_edit_form_validate

in drupal:11.4.0 and is removed from drupal:12.0.0. Use MediaHooks::formatEditFormValidate() instead.

Validate callback to ensure filter order and allowed_html are compatible.
template_preprocess_media

in drupal:11.3.0 and is removed from drupal:12.0.0. Initial template_preprocess functions are registered directly in hook_theme().

Prepares variables for media templates.
_media_get_add_url

in drupal:11.4.0 and is removed from drupal:12.0.0. There is no replacement.

Returns the appropriate URL to add media for the current user.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.