View source
<?php
require_once dirname(__FILE__) . '/nodehierarchy.api.inc';
require_once dirname(__FILE__) . '/nodehierarchy.admin.inc';
function nodehierarchy_views_api() {
return array(
'api' => 2,
'path' => drupal_get_path('module', 'nodehierarchy') . '/includes/views',
);
}
function nodehierarchy_migrate_api() {
$api = array(
'api' => 2,
'destination handlers' => array(
'MigrateNodeHierarchyHandler',
),
);
return $api;
}
function nodehierarchy_help($path, $arg) {
switch ($path) {
case 'admin/modules#description':
return t('A module to make nodes hierarchical.');
}
}
function nodehierarchy_permission() {
return array(
'create child nodes' => array(
'title' => t('create child nodes'),
'description' => t('Add a node as a child of another node'),
),
'edit all node parents' => array(
'title' => t('edit all node parents'),
'description' => t('Edit the parent of any node'),
),
'edit own node parents' => array(
'title' => t('edit own node parents'),
'description' => t('Edit the parent of own nodes'),
),
'administer hierarchy' => array(
'title' => t('administer hierarchy'),
'description' => t('Change the site wide settings for Node Hierarchy'),
),
'customize nodehierarchy menus' => array(
'title' => t('customize nodehierarchy menus'),
'description' => t('Change the menu settings for nodes'),
),
'create child of any parent' => array(
'title' => t('create child of any parent'),
'description' => t('Add a child to any other node'),
),
);
}
function nodehierarchy_menu() {
$items = array();
$items['admin/structure/nodehierarchy'] = array(
'title' => t('Node Hierarchy'),
'description' => t('Administer default Node Hierarchy settings.'),
'file' => 'nodehierarchy.admin.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'nodehierarchy_admin_settings',
),
'access arguments' => array(
'administer site configuration',
),
'type' => MENU_NORMAL_ITEM,
);
$items['node/%node/children'] = array(
'title' => t('Children'),
'page callback' => 'nodehierarchy_view_children',
'file' => 'nodehierarchy.admin.inc',
'page arguments' => array(
1,
),
'access callback' => 'nodehierarchy_children_tab_access',
'access arguments' => array(
1,
),
'type' => MENU_LOCAL_TASK,
'weight' => 5,
);
return $items;
}
function nodehierarchy_children_tab_access($node) {
module_load_include('inc', 'nodehierarchy', 'nodehierarchy.admin');
return node_access('update', $node) && nodehierarchy_node_can_be_parent($node);
}
function nodehierarchy_theme() {
return array(
'nodehierarchy_new_child_links' => array(
'variables' => array(
'node' => NULL,
),
'file' => 'nodehierarchy.admin.inc',
),
'nodehierarchy_children_form' => array(
'render element' => 'form',
'file' => 'nodehierarchy.admin.inc',
),
'nodehierarchy_parent_selector' => array(
'render element' => 'element',
'file' => 'nodehierarchy.admin.inc',
),
);
}
function nodehierarchy_content_extra_fields($type_name) {
module_load_include('inc', 'nodehierarchy', 'nodehierarchy.admin');
_nodehierarchy_content_extra_fields($type_name);
}
function nodehierarchy_form_alter(&$form, &$form_state, $form_id) {
global $user;
$type = isset($form['type']) && isset($form['#node']) ? $form['type']['#value'] : '';
switch ($form_id) {
case 'node_type_form':
module_load_include('inc', 'nodehierarchy', 'nodehierarchy.admin');
nodehierarchy_alter_node_type_form($form, $form_state, $form_id);
break;
case $type . '_node_form':
module_load_include('inc', 'nodehierarchy', 'nodehierarchy.admin');
nodehierarchy_alter_node_form($form, $form_state, $form_id);
break;
case 'node_delete_confirm':
module_load_include('inc', 'nodehierarchy', 'nodehierarchy.admin');
nodehierarchy_alter_node_delete_confirm_form($form, $form_state, $form_id);
break;
}
}
function nodehierarchy_nodehierarchy_node_form($node, $form, $form_state) {
module_load_include('inc', 'nodehierarchy', 'nodehierarchy.admin');
return _nodehierarchy_nodehierarchy_node_form($node, $form, $form_state);
}
function nodehierarchy_form_menu_edit_item_submit($form, &$form_state) {
$form_state['values']['parent'] = $form_state['values']['menu_name'] . ':' . _nodehierarchy_get_node_mlid($form_state['values']['pnid'], TRUE);
}
function nodehierarchy_node_insert($node) {
module_load_include('inc', 'nodehierarchy', 'nodehierarchy.admin');
nodehierarchy_insert_node($node);
}
function nodehierarchy_node_update($node) {
module_load_include('inc', 'nodehierarchy', 'nodehierarchy.admin');
nodehierarchy_update_node($node);
}
function nodehierarchy_node_prepare($node) {
module_load_include('inc', 'nodehierarchy', 'nodehierarchy.admin');
return nodehierarchy_prepare_node($node);
}
function nodehierarchy_node_load($nodes) {
foreach ($nodes as $nid => $node) {
$nid = empty($node->nid) ? null : $node->nid;
$node->nodehierarchy_parents = nodehierarchy_get_node_parents($nid);
}
}
function nodehierarchy_node_delete($node) {
module_load_include('inc', 'nodehierarchy', 'nodehierarchy.admin');
nodehierarchy_delete_node($node);
}
function nodehierarchy_node_view($node, $view_mode = 'full') {
if ($view_mode == 'full') {
nodehierarchy_set_breadcrumbs($node);
}
}
function nodehierarchy_node_submit($node, $form, $form_state) {
}
function nodehierarchy_nodehierarchy_default_parents($node) {
module_load_include('inc', 'nodehierarchy', 'nodehierarchy.admin');
_nodehierarchy_nodehierarchy_default_parents($node);
}
function nodehierarchy_set_breadcrumbs($node, $add_node = FALSE) {
$breadcrumb = array();
$nid = empty($node->nid) ? null : $node->nid;
$breadcrumb = nodehierarchy_get_breadcrumb($nid);
if ($add_node) {
$uri = entity_uri('node', $node);
$breadcrumb[] = l($node->title, $uri['path'], $uri['options']);
}
array_unshift($breadcrumb, l(t('Home'), '<front>'));
drupal_set_breadcrumb($breadcrumb);
}
function nodehierarchy_get_breadcrumb($nid) {
$breadcrumb = array();
$trail = nodehierarchy_get_node_primary_ancestor_nodes($nid);
foreach ($trail as $node) {
$uri = entity_uri('node', $node);
$breadcrumb[] = l($node->title, $uri['path'], $uri['options']);
}
return $breadcrumb;
}