Commit cc7876e1 authored by quietone's avatar quietone
Browse files

Issue #3264059 by andypost: Remove deprecated jsonapi module functions

parent a8ad60c5
Loading
Loading
Loading
Loading
+0 −10
Original line number Diff line number Diff line
@@ -250,13 +250,3 @@ services:
    class: Drupal\jsonapi\Controller\TemporaryJsonapiFileFieldUploader
    public: false
    arguments: ['@logger.channel.file', '@file_system', '@file.mime_type.guesser', '@token', '@lock', '@config.factory']

  # Deprecated services.
  access_check.jsonapi.relationship_field_access:
    # Deprecated in drupal:9.2.0 and is removed from drupal:10.0.0. There is no
    # replacement. JSON:API's access checkers are not part of its public API.
    # See https://www.drupal.org/node/3194641.
    class: Drupal\jsonapi\Access\RelationshipFieldAccess
    arguments: ['@jsonapi.entity_access_checker']
    tags:
      - { name: access_check, applies_to: _jsonapi_relationship_field_access, needs_incoming_request: TRUE }
+0 −78
Original line number Diff line number Diff line
<?php

namespace Drupal\jsonapi\Access;

use Drupal\Core\Access\AccessResultReasonInterface;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Http\Exception\CacheableAccessDeniedHttpException;
use Drupal\Core\Routing\Access\AccessInterface;
use Drupal\Core\Routing\RouteMatch;
use Drupal\Core\Session\AccountInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Route;

/**
 * Defines a class to check access to related and relationship routes.
 *
 * @todo Deprecated in drupal:9.2.0 and is removed from drupal:10.0.0. There is
 *   no replacement. JSON:API's access checkers are not part of its public API.
 *
 * @internal JSON:API maintains no PHP API. The API is the HTTP API. This class
 *   may change at any time and could break any dependencies on it.
 *
 * @see https://www.drupal.org/node/3194641
 * @see https://www.drupal.org/project/drupal/issues/3032787
 * @see jsonapi.api.php
 */
class RelationshipFieldAccess implements AccessInterface {

  /**
   * The route requirement key for this access check.
   *
   * @var string
   */
  const ROUTE_REQUIREMENT_KEY = '_jsonapi_relationship_field_access';

  /**
   * The JSON:API entity access checker.
   *
   * @var \Drupal\jsonapi\Access\EntityAccessChecker
   */
  protected $entityAccessChecker;

  /**
   * RelationshipFieldAccess constructor.
   *
   * @param \Drupal\jsonapi\Access\EntityAccessChecker $entity_access_checker
   *   The JSON:API entity access checker.
   */
  public function __construct(EntityAccessChecker $entity_access_checker) {
    $this->entityAccessChecker = $entity_access_checker;
  }

  /**
   * Checks access to the relationship field on the given route.
   *
   * @param \Symfony\Component\HttpFoundation\Request $request
   *   The incoming HTTP request object.
   * @param \Symfony\Component\Routing\Route $route
   *   The route to check against.
   * @param \Drupal\Core\Session\AccountInterface $account
   *   The currently logged in account.
   *
   * @return \Drupal\Core\Access\AccessResultInterface
   *   The access result.
   */
  public function access(Request $request, Route $route, AccountInterface $account) {
    @trigger_error(sprintf("The %s access check is deprecated in drupal:9.2.0 and is removed from drupal:10.0.0. There is no replacement. JSON:API's route access checks are internal. See https://www.drupal.org/node/3194641.", static::ROUTE_REQUIREMENT_KEY), E_USER_DEPRECATED);
    $relationship_route_access_checker = \Drupal::service('access_check.jsonapi.relationship_route_access');
    assert($relationship_route_access_checker instanceof RelationshipRouteAccessCheck);
    $access_result = $relationship_route_access_checker->access($route, RouteMatch::createFromRequest($request), $account);
    assert($access_result instanceof AccessResultReasonInterface);
    if (!$access_result->isAllowed() && $request->isMethodCacheable()) {
      throw new CacheableAccessDeniedHttpException(CacheableMetadata::createFromObject($access_result), $access_result->getReason());
    }
    return $access_result;
  }

}
+2 −7
Original line number Diff line number Diff line
@@ -128,15 +128,10 @@ class FieldResolver {
   *   The resource type repository.
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
   *   The module handler.
   * @param \Drupal\Core\Session\AccountInterface|null $current_user
   * @param \Drupal\Core\Session\AccountInterface $current_user
   *   The current user account.
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager, EntityFieldManagerInterface $field_manager, EntityTypeBundleInfoInterface $entity_type_bundle_info, ResourceTypeRepositoryInterface $resource_type_repository, ModuleHandlerInterface $module_handler, AccountInterface $current_user = NULL) {
    if (is_null($current_user)) {
      @trigger_error('Calling ' . __METHOD__ . '() without the $current_user argument is deprecated in drupal:9.3.0 and will be required in drupal:10.0.0.', E_USER_DEPRECATED);
      $current_user = \Drupal::currentUser();
    }

  public function __construct(EntityTypeManagerInterface $entity_type_manager, EntityFieldManagerInterface $field_manager, EntityTypeBundleInfoInterface $entity_type_bundle_info, ResourceTypeRepositoryInterface $resource_type_repository, ModuleHandlerInterface $module_handler, AccountInterface $current_user) {
    $this->currentUser = $current_user;
    $this->entityTypeManager = $entity_type_manager;
    $this->fieldManager = $field_manager;
+1 −5
Original line number Diff line number Diff line
@@ -79,11 +79,7 @@ class LinkCollectionNormalizer extends NormalizerBase {
   * @param \Drupal\Core\Session\AccountInterface $current_user
   *   The current user.
   */
  public function __construct(AccountInterface $current_user = NULL) {
    if (is_null($current_user)) {
      @trigger_error('Calling ' . __METHOD__ . '() without the $current_user argument is deprecated in drupal:9.2.0 and will be required in drupal:10.0.0.', E_USER_DEPRECATED);
      $current_user = \Drupal::currentUser();
    }
  public function __construct(AccountInterface $current_user) {
    $this->currentUser = $current_user;
  }