You are here

class ReplicateAccessChecker in Replicate UI 8

Access checker which checks entity create/view access as well a permission.

Hierarchy

Expanded class hierarchy of ReplicateAccessChecker

1 string reference to 'ReplicateAccessChecker'
replicate_ui.services.yml in ./replicate_ui.services.yml
replicate_ui.services.yml
1 service uses ReplicateAccessChecker
replicate_ui.access_check in ./replicate_ui.services.yml
\Drupal\replicate_ui\ReplicateAccessChecker

File

src/ReplicateAccessChecker.php, line 15

Namespace

Drupal\replicate_ui
View source
class ReplicateAccessChecker implements AccessInterface {

  /**
   * @var \Drupal\user\Access\PermissionAccessCheck
   */
  protected $permAccessChecker;

  /**
   * @var \Drupal\Core\Entity\EntityAccessCheck
   */
  protected $entityAccessChecker;

  /**
   * Creates a new ReplicateAccessChecker instance.
   *
   * @param \Drupal\user\Access\PermissionAccessCheck $permAccessChecker
   * @param \Drupal\Core\Entity\EntityAccessCheck $entityAccessChecker
   */
  public function __construct(PermissionAccessCheck $permAccessChecker, EntityAccessCheck $entityAccessChecker) {
    $this->permAccessChecker = $permAccessChecker;
    $this->entityAccessChecker = $entityAccessChecker;
  }
  public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account) {
    $create_fake_route = clone $route;
    $create_fake_route
      ->setRequirement('_entity_access', $route
      ->getDefault('entity_type_id') . '.create');
    $view_fake_route = clone $route;
    $view_fake_route
      ->setRequirement('_entity_access', $route
      ->getDefault('entity_type_id') . '.create');
    $permission_fake_route = clone $route;
    $permission_fake_route
      ->setRequirements([
      '_permission' => 'replicate entities',
    ]);
    return $this->entityAccessChecker
      ->access($view_fake_route, $route_match, $account)
      ->andIf($this->entityAccessChecker
      ->access($create_fake_route, $route_match, $account))
      ->andIf($this->permAccessChecker
      ->access($permission_fake_route, $account));
  }

  /**
   * {@inheritdoc}
   */
  public function applies(Route $route) {
  }

}

Members