- <?php
- * @file
- * A dummy module for testing node related hooks.
- *
- * This is a dummy module that implements node related hooks to test API
- * interaction with the Node module.
- */
-
- * Implements hook_node_load().
- */
- function node_test_node_load($nodes, $types) {
-
-
-
- $nids = array_keys($nodes);
- ksort($nids);
- sort($types);
- foreach ($nodes as $node) {
- $node->node_test_loaded_nids = $nids;
- $node->node_test_loaded_types = $types;
- }
- }
-
- * Implements hook_node_view().
- */
- function node_test_node_view(Node $node, $view_mode) {
- if ($view_mode == 'rss') {
-
- $node->rss_elements[] = array(
- 'key' => 'testElement',
- 'value' => t('Value of testElement RSS element for node !nid.', array('!nid' => $node->nid)),
- );
- $node->rss_namespaces['xmlns:backdroptest'] = 'http://example.com/test-namespace';
-
-
- $node->content['extra_feed_content'] = array(
- '#type' => 'help',
- '#markup' => t('Extra data that should appear only in the RSS feed for node !nid.', array('!nid' => $node->nid)),
- '#weight' => 10,
- );
- }
-
- if ($view_mode != 'rss') {
-
- $node->content['extra_non_feed_content'] = array(
- '#type' => 'help',
- '#markup' => t('Extra data that should appear everywhere except the RSS feed for node !nid.', array('!nid' => $node->nid)),
- );
- }
- }
-
- * Implements hook_node_grants().
- */
- function node_test_node_grants($account, $op) {
-
-
-
- return array(
- 'test_post_realm' => array(1),
- 'test_page_realm' => array(1),
- 'test_alter_realm' => array(2),
- );
- }
-
- * Implements hook_node_access_records().
- */
- function node_test_node_access_records(Node $node) {
-
- if (!empty($node->disable_node_access)) {
- return;
- }
- $grants = array();
- if ($node->type == 'post') {
-
- $grants[] = array(
- 'realm' => 'test_post_realm',
- 'gid' => 1,
- 'grant_view' => 1,
- 'grant_update' => 0,
- 'grant_delete' => 0,
- 'priority' => 0,
- );
- }
- elseif ($node->type == 'page') {
-
- $grants[] = array(
- 'realm' => 'test_page_realm',
- 'gid' => 1,
- 'grant_view' => 1,
- 'grant_update' => 0,
- 'grant_delete' => 0,
- 'priority' => 0,
- );
- }
- return $grants;
- }
-
- * Implements hook_node_access_records_alter().
- */
- function node_test_node_access_records_alter(&$grants, Node $node) {
- if (!empty($grants)) {
- foreach ($grants as $key => $grant) {
-
- if ($grant['realm'] == 'test_page_realm' && $node->promote) {
- $grants[$key]['realm'] = 'test_alter_realm';
- $grants[$key]['gid'] = 2;
- }
- }
- }
- }
-
- * Implements hook_node_grants_alter().
- */
- function node_test_node_grants_alter(&$grants, $account, $op) {
-
- $grants = array();
- }
-
- * Implements hook_node_presave().
- */
- function node_test_node_presave(Node $node) {
- if ($node->title == 'testing_node_presave') {
-
- $node->created = 1421394600;
-
- $node->changed = 1474011660;
- }
-
- if (!empty($node->original) && $node->original->title == 'test_changes') {
- if ($node->original->title != $node->title) {
- $node->title .= '_presave';
- }
- }
- }
-
- * Implements hook_node_update().
- */
- function node_test_node_update(Node $node) {
-
- if (!empty($node->original) && $node->original->title == 'test_changes') {
- if ($node->original->title != $node->title) {
- $node->title .= '_update';
- }
- }
- }
-
- * Implements hook_entity_view_mode_alter().
- */
- function node_test_entity_view_mode_alter(&$view_mode, $context) {
-
- if ($change_view_mode = state_get('node_test_change_view_mode', '')) {
- $view_mode = $change_view_mode;
- }
- }
-
- * Implements hook_node_insert().
- *
- * This tests saving a node on node insert.
- *
- * @see NodeSaveTest::testNodeSaveOnInsert()
- */
- function node_test_node_insert($node) {
-
- if ($node->title == 'new') {
- $node->title = 'Node '. $node->nid;
-
-
- unset($node->is_new);
- node_save($node);
- }
- }