drupal 8路由yml entity_access

时间:2014-08-23 08:15:11

标签: drupal drupal-8

在drupal 8中的module.routing.yml文件中, 函数“node.view”在哪里,如

_entity_access:'node.view'

来源: https://api.drupal.org/api/drupal/core!modules!book!book.routing.yml/8

提前谢谢你

1 个答案:

答案 0 :(得分:4)

简单地说,_entity_access: node.view在Drupal 8中的module.routing.yml文件中意味着"调用node实体中定义的访问处理程序并提供view作为操作正在检查访问权限"。

访问处理程序在实体类型注释中的access处理程序条目中定义。例如。对于节点实体

/**
 * Defines the node entity class.
 *
 * @ContentEntityType(
 *   id = "node",
 *   label = @Translation("Content"),
 *   bundle_label = @Translation("Content type"),
 *   handlers = {
 *     "access" = "Drupal\node\NodeAccessControlHandler",
 *   }
 * )
 */

因此,在回调\Drupal\node\NodeAccessControlHandler::access()查看代码时,$operation参数会保留值'view'

public function access(EntityInterface $entity, $operation, $langcode = LanguageInterface::LANGCODE_DEFAULT, AccountInterface $account = NULL, $return_as_object = FALSE) {
  $account = $this->prepareUser($account);

  if ($account->hasPermission('bypass node access')) {
    $result = AccessResult::allowed()->cachePerPermissions();
    return $return_as_object ? $result : $result->isAllowed();
  }
  if (!$account->hasPermission('access content')) {
    $result = AccessResult::forbidden()->cachePerPermissions();
    return $return_as_object ? $result : $result->isAllowed();
  }
  $result = parent::access($entity, $operation, $langcode, $account, TRUE)->cachePerPermissions();
  return $return_as_object ? $result : $result->isAllowed();
}