You are here

menu_node_test.module in Menu Node API 7

Test module for Menu Node API hooks.

File

tests/menu_node_test.module
View source
<?php

/**
 * @file
 *   Test module for Menu Node API hooks.
 */

/**
 * Store static variables to indicate that hooks fired.
 */
function menu_node_test_set($value = NULL) {
  static $storage;
  if (is_null($value) && isset($storage)) {
    return $storage;
  }
  $storage = $value;
}

/**
 * Get the static value.
 */
function menu_node_test_get() {
  return menu_node_test_set();
}

/**
 * Implements hook_menu_node_invoke_insert().
 */
function menu_node_test_menu_node_invoke_insert($link, $node) {

  // On insert, increment the count and set a static indicator, so we
  // can count how many times this operation has run.
  $i =& drupal_static(__FUNCTION__);
  if (!empty($link->mlid) && !empty($node->nid)) {
    menu_node_test_set('insert' . $i++);
  }
}

/**
 * Implements hook_menu_node_invoke_update().
 */
function menu_node_test_menu_node_invoke_update($link, $node) {
  $i =& drupal_static(__FUNCTION__);
  if (!empty($link->mlid) && !empty($node->nid)) {
    menu_node_test_set('update' . $i++);
  }
}

/**
 * Implements hook_menu_node_invoke_delete().
 */
function menu_node_test_menu_node_invoke_delete($link, $node) {
  $i =& drupal_static(__FUNCTION__);
  if (!empty($link->mlid) && !empty($node->nid)) {
    menu_node_test_set('delete' . $i++);
  }
}