You are here

public function AbstractEntityFormModesFactory::checkAccess in Form mode manager 8.2

Return value

\Drupal\Core\Access\AccessResult If form mode is active, isAllowed() will be TRUE, otherwise isForbidden() will be TRUE.

Overrides EntityFormModeManagerInterface::checkAccess

1 method overrides AbstractEntityFormModesFactory::checkAccess()
SimpleEntityFormModes::checkAccess in src/SimpleEntityFormModes.php
Checks access for the Form Mode Manager routes.

File

src/AbstractEntityFormModesFactory.php, line 154

Class

AbstractEntityFormModesFactory
Abstract Factory to generate object used by routing of Form Mode Manager.

Namespace

Drupal\form_mode_manager

Code

public function checkAccess(RouteMatchInterface $route_match) {
  $route_object = $route_match
    ->getRouteObject();

  /** @var \Drupal\Core\Entity\EntityInterface $entity */
  $entity = $this
    ->getEntityFromRouteMatch($route_match);
  $bundle_id = $this
    ->getBundleEntityTypeId($entity, $route_match);
  $form_mode_id = $route_object
    ->getDefault('_entity_form');
  $cache_tags = $this->formModeManager
    ->getListCacheTags();

  // When we need to check access for actions links,
  // we don't have entity to load.
  if (empty($entity)) {
    $entity_type_id = $route_object
      ->getOption('_form_mode_manager_entity_type_id');
  }
  $entity_type_id = isset($entity_type_id) ? $entity_type_id : $entity
    ->getEntityTypeId();
  $operation = $this
    ->getFormModeOperationName($this->formModeManager
    ->getFormModeMachineName($form_mode_id));
  $is_active_form_mode = $this->formModeManager
    ->isActive($entity_type_id, $bundle_id, $operation);
  return AccessResult::allowedIf($is_active_form_mode)
    ->addCacheTags($cache_tags)
    ->addCacheableDependency($entity);
}