acl_node_test.module in ACL 8
Dummy module implementing node related hooks to test API interaction with the Node module.
File
tests/modules/acl_node_test/acl_node_test.moduleView source
<?php
/**
* @file
* Dummy module implementing node related hooks to test API interaction with
* the Node module.
*/
use Drupal\node\NodeInterface;
/**
* Implements hook_enabled().
*/
function acl_node_test_enabled() {
// Required for ACL hook_node_access_records().
return TRUE;
}
/**
* Implements hook_node_grants().
*/
function acl_node_test_node_grants($account, $op) {
// Give everyone full grants so we don't break other node tests.
// Our node access tests asserts three realms of access.
// See testGrantAlter().
$grants = array();
foreach (node_type_get_names() as $type) {
$grants['test_' . $type . '_realm'] = array(
1,
);
}
$grants['test_alter_realm'] = array(
2,
);
return $grants;
}
/**
* Implements hook_node_access_records().
*
* Implicit View by All is allowed.
*/
function acl_node_test_node_access_records(NodeInterface $node) {
$grants = array();
$grants[] = array(
'realm' => 'test_' . $node
->getType() . '_realm',
'gid' => 1,
'grant_view' => 1,
'grant_update' => 0,
'grant_delete' => 0,
'priority' => 0,
);
return $grants;
}
/**
* Implements hook_node_access_records_alter().
*/
function acl_node_test_node_access_records_alter(&$grants, NodeInterface $node) {
if (!empty($grants)) {
foreach ($grants as $key => $grant) {
// Alter grant from test_page_realm to test_alter_realm and modify the gid.
if ($grant['realm'] == 'test_test_alter_realm' && $node
->isPromoted()) {
$grants[$key]['realm'] = 'test_alter_realm';
$grants[$key]['gid'] = 2;
}
}
}
}
/**
* Implements hook_node_grants_alter().
*
* Returns an empty array of grants to prove that we can alter by reference.
*/
function acl_node_test_node_grants_alter(&$grants, $account, $op) {
$grants = array();
}
/**
* Implements hook_node_presave().
*/
function acl_node_test_node_presave(NodeInterface $node) {
if ($node
->getTitle() == 'testing_node_presave') {
// Sun, 19 Nov 1978 05:00:00 GMT
$node
->setCreatedTime(280299600);
// Drupal 1.0 release.
$node
->set('changed', 979534800);
}
}
Functions
Name | Description |
---|---|
acl_node_test_enabled | Implements hook_enabled(). |
acl_node_test_node_access_records | Implements hook_node_access_records(). |
acl_node_test_node_access_records_alter | Implements hook_node_access_records_alter(). |
acl_node_test_node_grants | Implements hook_node_grants(). |
acl_node_test_node_grants_alter | Implements hook_node_grants_alter(). |
acl_node_test_node_presave | Implements hook_node_presave(). |