public function ViewModeAccessCheck::access

Checks for access to route.

Parameters

\Symfony\Component\Routing\Route $route: The route to check against.

\Symfony\Component\HttpFoundation\Request $request: The request object.

Return value

mixed TRUE if access is allowed. FALSE if not. NULL if no opinion.

Overrides AccessCheckInterface::access

File

drupal/core/modules/field_ui/lib/Drupal/field_ui/Access/ViewModeAccessCheck.php, line 29
Contains \Drupal\field_ui\Access\ViewModeAccessCheck.

Class

ViewModeAccessCheck
Allows access to routes to be controlled by an '_access' boolean parameter.

Namespace

Drupal\field_ui\Access

Code

public function access(Route $route, Request $request) {
  if ($entity_type = $request->attributes
    ->get('entity_type')) {
    $bundle = $request->attributes
      ->get('bundle');
    $view_mode = $request->attributes
      ->get('view_mode');
    $view_mode_settings = field_view_mode_settings($entity_type, $bundle);
    $visibility = $view_mode == 'default' || !empty($view_mode_settings[$view_mode]['status']);
    if ($visibility) {
      $permission = $route
        ->getRequirement('_field_ui_view_mode_access');
      return user_access($permission);
    }
  }
}