Drupal API

hook_node_access_records

  • Drupal 5
  • Drupal 6

developer/hooks/core.php, строка 1211

Версии
5 – 6
hook_node_access_records($node)

Устанавливает разрешения для ноды быть записанной в базу данных.

Когда нода сохранена, a module implementing node access will be asked if it is interested in the access permissions to a node. If it is interested, it must respond with an array of array of permissions for that node.

Каждая единица в массиве:

'realm' This should only be realms for which the module has returned grant IDs in hook_node_grants. 'gid' This is a 'grant ID', which can have an arbitrary meaning per realm. 'grant_view' If set to TRUE a user with the gid in the realm can view this node. 'grant_edit' If set to TRUE a user with the gid in the realm can edit this node. 'grant_delete' If set to TRUE a user with the gid in the realm can delete this node. 'priority' If multiple modules seek to set permissions on a node, the realms that have the highest priority will win out, and realms with a lower priority will not be written. If there is any doubt, it is best to leave this 0.

Связанные темы

▸ 1 функция вызывает hook_node_access_records()

▾ 1 функция вызывает hook_node_access_records()

node_access_acquire_grants in modules/node/node.module
This function will call module invoke to get a list of grants and then write them to the database. It is called at node save, and should be called by modules whenever something other than a node_save causes the permissions on a node to change.

Код

<?php
function hook_node_access_records($node) {
  if (node_access_example_disabling()) {
    return;
  }
  // We only care about the node if it's been marked private. If not, it is
  // treated just like any other node and we completely ignore it.
  if ($node->private) {
    $grants = array();
    $grants[] = array(
      'realm' => 'example',
      'gid' => TRUE,
      'grant_view' => TRUE,
      'grant_update' => FALSE,
      'grant_delete' => FALSE,
      'priority' => 0,
    );
    // For the example_author array, the GID is equivalent to a UID, which
    // means there are many many groups of just 1 user.
    $grants[] = array(
      'realm' => 'example_author',
      'gid' => $node->uid,
      'grant_view' => TRUE,
      'grant_update' => TRUE,
      'grant_delete' => TRUE,
      'priority' => 0,
    );
    return $grants;
  }
}
?>
Войдите или зарегистрируйтесь, чтобы получить возможность отправлять комментарии

Вход в систему

Что такое OpenID?
  • Регистрация
  • Забыли пароль?

Документация

  • Drupal 6
  • Константы
  • Файлы
  • Функции
  • Глобальные переменные
  • Разделы