public function SimpleEntityFormModes::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 AbstractEntityFormModesFactory::checkAccess
File
- src/
SimpleEntityFormModes.php, line 26
Class
- SimpleEntityFormModes
- Route controller factory specific for each entities not using bundles.
Namespace
Drupal\form_mode_managerCode
public function checkAccess(RouteMatchInterface $route_match) {
/** @var \Drupal\Core\Entity\EntityInterface $entity */
$entity = $this
->getEntityFromRouteMatch($route_match);
$route = $route_match
->getRouteObject();
$form_mode_id = $route
->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)) {
$route_entity_type_info = $this
->getEntityTypeFromRouteMatch($route_match);
$entity_type_id = $route_entity_type_info['entity_type_id'];
}
$entity_type_id = isset($entity_type_id) ? $entity_type_id : $entity
->getEntityTypeId();
$operation = $this
->getFormModeOperationName($this->formModeManager
->getFormModeMachineName($form_mode_id));
return AccessResult::allowedIf($this->formModeManager
->isActive($entity_type_id, $entity_type_id, $operation))
->addCacheTags($cache_tags)
->addCacheableDependency($entity);
}