public function ViewModeAccessCheck::access in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/field_ui/src/Access/ViewModeAccessCheck.php \Drupal\field_ui\Access\ViewModeAccessCheck::access()
Checks access to the view mode.
Parameters
\Symfony\Component\Routing\Route $route: The route to check against.
\Drupal\Core\Routing\RouteMatchInterface $route_match: The parametrized route.
\Drupal\Core\Session\AccountInterface $account: The currently logged in account.
string $view_mode_name: (optional) The view mode. Defaults to 'default'.
string $bundle: (optional) The bundle. Different entity types can have different names for their bundle key, so if not specified on the route via a {bundle} parameter, the access checker determines the appropriate key name, and gets the value from the corresponding request attribute. For example, for nodes, the bundle key is "node_type", so the value would be available via the {node_type} parameter rather than a {bundle} parameter.
Return value
\Drupal\Core\Access\AccessResultInterface The access result.
File
- core/
modules/ field_ui/ src/ Access/ ViewModeAccessCheck.php, line 64 - Contains \Drupal\field_ui\Access\ViewModeAccessCheck.
Class
- ViewModeAccessCheck
- Defines an access check for entity view mode routes.
Namespace
Drupal\field_ui\AccessCode
public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account, $view_mode_name = 'default', $bundle = NULL) {
$access = AccessResult::neutral();
if ($entity_type_id = $route
->getDefault('entity_type_id')) {
if (empty($bundle)) {
$entity_type = $this->entityManager
->getDefinition($entity_type_id);
$bundle = $route_match
->getRawParameter($entity_type
->getBundleEntityType());
}
$visibility = FALSE;
if ($view_mode_name == 'default') {
$visibility = TRUE;
}
elseif ($entity_display = $this->entityManager
->getStorage('entity_view_display')
->load($entity_type_id . '.' . $bundle . '.' . $view_mode_name)) {
$visibility = $entity_display
->status();
}
if ($view_mode_name != 'default' && $entity_display) {
$access
->cacheUntilEntityChanges($entity_display);
}
if ($visibility) {
$permission = $route
->getRequirement('_field_ui_view_mode_access');
$access = $access
->orIf(AccessResult::allowedIfHasPermission($account, $permission));
}
}
return $access;
}