Commit d47cd984 authored by catch's avatar catch
Browse files

Issue #3244802 by andypost, Spokje, catch, dww: Remove BC layers in entity system

parent 637ccc1a
Loading
Loading
Loading
Loading
+0 −7
Original line number Diff line number Diff line
@@ -1163,13 +1163,6 @@ services:
    class: Drupal\Core\Entity\EntityAccessCheck
    tags:
      - { name: access_check, applies_to: _entity_access }
  access_check.entity_bundles:
    # Deprecated in drupal:9.2.0 and is removed from drupal:10.0.0. Specify the
    # list of bundles in the entity parameter, under "bundle" key as a sequence,
    # instead. See https://www.drupal.org/node/3155569.
    class: Drupal\Core\Entity\EntityBundleAccessCheck
    tags:
      - { name: access_check, applies_to: _entity_bundles }
  access_check.entity_create:
    class: Drupal\Core\Entity\EntityCreateAccessCheck
    arguments: ['@entity_type.manager']
+0 −58
Original line number Diff line number Diff line
<?php

namespace Drupal\Core\Entity;

use Drupal\Core\Access\AccessResult;
use Drupal\Core\Routing\Access\AccessInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Session\AccountInterface;
use Symfony\Component\Routing\Route;

/**
 * Provides an entity bundle checker for the _entity_bundles route requirement.
 *
 * @todo Deprecated in drupal:9.2.0 and is removed from drupal:10.0.0. Specify
 *   the list of bundles in the entity parameter, under "bundle" key, as a
 *   sequence, instead.
 *
 * @see https://www.drupal.org/node/3155569
 */
class EntityBundleAccessCheck implements AccessInterface {

  /**
   * Checks entity bundle match based on the _entity_bundles route requirement.
   *
   * @code
   * example.route:
   *   path: foo/{example_entity_type}/{other_parameter}
   *   requirements:
   *     _entity_bundles: 'example_entity_type:example_bundle|other_example_bundle'
   * @endcode
   *
   * @param \Symfony\Component\Routing\Route $route
   *   The route to check against.
   * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
   *   The parametrized route.
   * @param \Drupal\Core\Session\AccountInterface $account
   *   The currently logged in account.
   *
   * @return \Drupal\Core\Access\AccessResultInterface
   *   The access result.
   */
  public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account) {
    @trigger_error('The ' . __NAMESPACE__ . '\EntityBundleAccessCheck is deprecated in drupal:9.2.0 and is removed from drupal:10.0.0. Specify the list of bundles in the entity parameter, under "bundle" key, as a sequence, instead. See https://www.drupal.org/node/3155569', E_USER_DEPRECATED);
    if ($route->hasRequirement('_entity_bundles')) {
      [$entity_type, $bundle_definition] = explode(':', $route->getRequirement('_entity_bundles'));
      $bundles = explode('|', $bundle_definition);
      $parameters = $route_match->getParameters();
      if ($parameters->has($entity_type)) {
        $entity = $parameters->get($entity_type);
        if ($entity instanceof EntityInterface && in_array($entity->bundle(), $bundles, TRUE)) {
          return AccessResult::allowed()->addCacheableDependency($entity);
        }
      }
    }
    return AccessResult::neutral('The entity bundle does not match the route _entity_bundles requirement.');
  }

}
+0 −34
Original line number Diff line number Diff line
@@ -115,40 +115,6 @@ public function getEntityClass(?string $bundle = NULL): string {
    return $this->baseEntityClass;
  }

  /**
   * Warns subclasses not to directly access the deprecated entityClass property.
   *
   * @param string $name
   *   The name of the property to get.
   *
   * @todo Remove this in Drupal 10.
   * @see https://www.drupal.org/project/drupal/issues/3244802
   */
  public function __get($name) {
    if ($name === 'entityClass') {
      @trigger_error('Accessing the entityClass property directly is deprecated in drupal:9.3.0. Use ::getEntityClass() instead. See https://www.drupal.org/node/3191609', E_USER_DEPRECATED);
      return $this->getEntityClass();
    }
  }

  /**
   * Warns subclasses not to directly set the deprecated entityClass property.
   *
   * @param string $name
   *   The name of the property to set.
   * @param mixed $value
   *   The value to use.
   *
   * @todo Remove this in Drupal 10.
   * @see https://www.drupal.org/project/drupal/issues/3244802
   */
  public function __set(string $name, $value): void {
    if ($name === 'entityClass') {
      @trigger_error('Setting the entityClass property directly is deprecated in drupal:9.3.0 and has no effect in drupal:10.0.0. See https://www.drupal.org/node/3191609', E_USER_DEPRECATED);
      $this->baseEntityClass = $value;
    }
  }

  /**
   * {@inheritdoc}
   */
+0 −8
Original line number Diff line number Diff line
@@ -431,14 +431,6 @@ public function entityClassImplements($interface) {
    return is_subclass_of($this->getClass(), $interface);
  }

  /**
   * {@inheritdoc}
   */
  public function isSubclassOf($class) {
    @trigger_error(__METHOD__ . '() is deprecated in drupal:8.3.0 and is removed from drupal:10.0.0. Use Drupal\Core\Entity\EntityTypeInterface::entityClassImplements() instead. See https://www.drupal.org/node/2842808', E_USER_DEPRECATED);
    return $this->entityClassImplements($class);
  }

  /**
   * {@inheritdoc}
   */
+0 −17
Original line number Diff line number Diff line
@@ -360,23 +360,6 @@ public function setAccessClass($class);
   */
  public function entityClassImplements($interface);

  /**
   * Indicates if the entity type is a subclass of the given class or interface.
   *
   * @param string $class
   *   The class or interface to check.
   *
   * @return bool
   *   TRUE if the entity type is a subclass of the class or interface.
   *
   * @deprecated in drupal:8.3.0 and is removed from drupal:10.0.0.
   *   Use Drupal\Core\Entity\EntityTypeInterface::entityClassImplements()
   *   instead.
   *
   * @see https://www.drupal.org/node/2842808
   */
  public function isSubclassOf($class);

  /**
   * Sets the handlers for a given type.
   *
Loading