Commit 64079361 authored by catch's avatar catch
Browse files

Issue #3264057 by andypost, daffie, quietone: Remove deprecated media system functions

parent 5ac3d364
Loading
Loading
Loading
Loading
+0 −6
Original line number Diff line number Diff line
@@ -2,12 +2,6 @@ services:
  plugin.manager.media.source:
    class: Drupal\media\MediaSourceManager
    parent: default_plugin_manager
  access_check.media.revision:
    class: Drupal\media\Access\MediaRevisionAccessCheck
    arguments: ['@entity_type.manager']
    tags:
      - { name: access_check, applies_to: _access_media_revision }
    deprecated: The "%service_id%" service is deprecated. You should use the 'access_check.entity' service instead. See https://www.drupal.org/node/3161210
  media.oembed.url_resolver:
    class: Drupal\media\OEmbed\UrlResolver
    arguments: ['@media.oembed.provider_repository', '@media.oembed.resource_fetcher', '@http_client', '@module_handler', '@cache.default']
+0 −97
Original line number Diff line number Diff line
<?php

namespace Drupal\media\Access;

use Drupal\Core\Access\AccessResult;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Routing\Access\AccessInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\media\MediaInterface;
use Symfony\Component\Routing\Route;

/**
 * Provides an access checker for media item revisions.
 *
 * @ingroup media_access
 */
class MediaRevisionAccessCheck implements AccessInterface {

  /**
   * The media storage.
   *
   * @var \Drupal\Core\Entity\ContentEntityStorageInterface
   */
  protected $mediaStorage;

  /**
   * The media access control handler.
   *
   * @var \Drupal\Core\Entity\EntityAccessControlHandlerInterface
   */
  protected $mediaAccess;

  /**
   * Constructs a new MediaRevisionAccessCheck.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager) {
    @trigger_error('MediaRevisionAccessCheck is deprecated in drupal:9.3.0 and will be removed before drupal:10.0.0. Use "_entity_access" requirement with relevant operation instead. See https://www.drupal.org/node/3161210', E_USER_DEPRECATED);

    $this->mediaStorage = $entity_type_manager->getStorage('media');
    $this->mediaAccess = $entity_type_manager->getAccessControlHandler('media');
  }

  /**
   * Checks routing access for the media item revision.
   *
   * @param \Symfony\Component\Routing\Route $route
   *   The route to check against.
   * @param \Drupal\Core\Session\AccountInterface $account
   *   The currently logged in account.
   * @param int $media_revision
   *   (optional) The media item revision ID. If not specified, but $media is,
   *   access is checked for that object's revision.
   * @param \Drupal\media\MediaInterface $media
   *   (optional) A media item. Used for checking access to a media items
   *   default revision when $media_revision is unspecified. Ignored when
   *   $media_revision is specified. If neither $media_revision nor $media are
   *   specified, then access is denied.
   *
   * @return \Drupal\Core\Access\AccessResultInterface
   *   The access result.
   */
  public function access(Route $route, AccountInterface $account, $media_revision = NULL, MediaInterface $media = NULL) {
    if ($media_revision) {
      $media = $this->mediaStorage->loadRevision($media_revision);
    }
    $operation = $route->getRequirement('_access_media_revision');
    return AccessResult::allowedIf($media && $this->checkAccess($media, $account, $operation))->cachePerPermissions()->addCacheableDependency($media);
  }

  /**
   * Checks media item revision access.
   *
   * @param \Drupal\media\MediaInterface $media
   *   The media item to check.
   * @param \Drupal\Core\Session\AccountInterface $account
   *   A user object representing the user for whom the operation is to be
   *   performed.
   * @param string $op
   *   (optional) The specific operation being checked. Defaults to 'view'.
   *
   * @return bool
   *   TRUE if the operation may be performed, FALSE otherwise.
   */
  public function checkAccess(MediaInterface $media, AccountInterface $account, $op = 'view') {
    if (!$media || $op !== 'view') {
      // If there was no media to check against, or the $op was not one of the
      // supported ones, we return access denied.
      return FALSE;
    }

    return $this->mediaAccess->access($media, 'view all revisions', $account);
  }

}
+2 −6
Original line number Diff line number Diff line
@@ -28,15 +28,11 @@ class MediaAccessControlHandler extends EntityAccessControlHandler implements En
   *
   * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
   *   The entity type definition.
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface|null $entity_type_manager
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   */
  public function __construct(EntityTypeInterface $entity_type, EntityTypeManagerInterface $entity_type_manager = NULL) {
  public function __construct(EntityTypeInterface $entity_type, EntityTypeManagerInterface $entity_type_manager) {
    parent::__construct($entity_type);
    if (!isset($entity_type_manager)) {
      @trigger_error('Calling ' . __METHOD__ . '() without the $entity_type_manager argument is deprecated in drupal:9.3.0 and will be required in drupal:10.0.0. See https://www.drupal.org/node/3214171', E_USER_DEPRECATED);
      $entity_type_manager = \Drupal::entityTypeManager();
    }
    $this->entityTypeManager = $entity_type_manager;
  }

+1 −26
Original line number Diff line number Diff line
@@ -5,7 +5,6 @@
use Drupal\Component\Datetime\TimeInterface;
use Drupal\Component\Serialization\Json;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait;
use Drupal\Core\KeyValueStore\KeyValueFactoryInterface;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use GuzzleHttp\ClientInterface;
@@ -16,17 +15,6 @@
 */
class ProviderRepository implements ProviderRepositoryInterface {

  use DeprecatedServicePropertyTrait;

  /**
   * The service properties that should raise a deprecation error.
   *
   * @var string[]
   */
  private $deprecatedProperties = [
    'cacheBackend' => 'cache.default',
  ];

  /**
   * How long the provider data should be cached, in seconds.
   *
@@ -85,23 +73,10 @@ class ProviderRepository implements ProviderRepositoryInterface {
   * @param int $max_age
   *   (optional) How long the cache data should be kept. Defaults to a week.
   */
  public function __construct(ClientInterface $http_client, ConfigFactoryInterface $config_factory, TimeInterface $time, $key_value_factory = NULL, $logger_factory = NULL, int $max_age = 604800) {
  public function __construct(ClientInterface $http_client, ConfigFactoryInterface $config_factory, TimeInterface $time, KeyValueFactoryInterface $key_value_factory, LoggerChannelFactoryInterface $logger_factory, int $max_age = 604800) {
    $this->httpClient = $http_client;
    $this->providersUrl = $config_factory->get('media.settings')->get('oembed_providers_url');
    $this->time = $time;
    if (!($key_value_factory instanceof KeyValueFactoryInterface)) {
      @trigger_error('The keyvalue service should be passed to ' . __METHOD__ . '() since drupal:9.3.0 and is required in drupal:10.0.0. See https://www.drupal.org/node/3186186', E_USER_DEPRECATED);
      $key_value_factory = \Drupal::service('keyvalue');
    }
    if (!($logger_factory instanceof LoggerChannelFactoryInterface)) {
      // If $max_age was passed in $logger_factory's position, ensure that we
      // use the correct value.
      if (is_numeric($logger_factory)) {
        $max_age = $logger_factory;
      }
      @trigger_error('The logger.factory service should be passed to ' . __METHOD__ . '() since drupal:9.3.0 and is required in drupal:10.0.0. See https://www.drupal.org/node/3186186', E_USER_DEPRECATED);
      $logger_factory = \Drupal::service('logger.factory');
    }
    $this->maxAge = $max_age;
    $this->keyValue = $key_value_factory->get('media');
    $this->logger = $logger_factory->get('media');
+1 −5
Original line number Diff line number Diff line
@@ -44,13 +44,9 @@ class ResourceFetcher implements ResourceFetcherInterface {
   * @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
   *   The cache backend.
   */
  public function __construct(ClientInterface $http_client, ProviderRepositoryInterface $providers, CacheBackendInterface $cache_backend = NULL) {
  public function __construct(ClientInterface $http_client, ProviderRepositoryInterface $providers, CacheBackendInterface $cache_backend) {
    $this->httpClient = $http_client;
    $this->providers = $providers;
    if (empty($cache_backend)) {
      $cache_backend = \Drupal::cache();
      @trigger_error('Passing NULL as the $cache_backend parameter to ' . __METHOD__ . '() is deprecated in drupal:9.3.0 and is removed from drupal:10.0.0. See https://www.drupal.org/node/3223594', E_USER_DEPRECATED);
    }
    $this->cacheBackend = $cache_backend;
  }

Loading