nodeconnect.module in Node Connect 7
Handles the main hooks used by nodeconnect
One will find most of the meat in the form and menu includes
File
nodeconnect.moduleView source
<?php
/**
* @file
* Handles the main hooks used by nodeconnect
*
* One will find most of the meat in the form and menu includes
*/
/**
* Implements hook_menu().
*/
function nodeconnect_menu() {
return array(
'admin/nodeconnect/return/%' => array(
'page callback' => 'nodeconnect_return',
'page arguments' => array(
3,
),
'access callback' => TRUE,
'file' => 'nodeconnect.menu.inc',
),
'admin/nodeconnect/edit/%' => array(
'page callback' => 'nodeconnect_edit',
'page arguments' => array(
3,
),
'access callback' => TRUE,
'file' => 'nodeconnect.menu.inc',
),
'admin/nodeconnect/add/%' => array(
'title' => "Choose node type to create and add",
'page callback' => 'nodeconnect_add',
'page arguments' => array(
3,
),
'access callback' => TRUE,
'file' => 'nodeconnect.menu.inc',
),
);
}
/**
* Implements hook_field_attache_form().
*/
function nodeconnect_field_attach_form($entity_type, $entity, &$form, &$form_state, $langcode) {
foreach (_nodeconnect_get_ref_fields() as $field_name => $field) {
if (isset($form[$field_name])) {
nodeconnect_include_form();
_nodeconnect_field_attach_form($entity_type, $entity, $form, $form_state, $langcode, $field_name, $field);
}
}
}
/**
* Includes the form inc file
*
* This can be used in #submit array before the sumbit functions which are
* located in the inc file
*/
function nodeconnect_include_form() {
module_load_include("inc", "nodeconnect", "nodeconnect.form");
}
/**
* Implements hook_form_node_form_alter()
*
* If we are adding a new node we pass of to nodeconnect_add_node_form_alter().
* If we are returning to the parent node we hand off to nodequeue_return_node_form_alter
* TODO: need to move this at somepoint so it can be with any entity
*/
function nodeconnect_form_node_form_alter(&$form, &$form_state, $form_id) {
$child = isset($_REQUEST['child']);
// We can get the cid two different ways
// First we try the $_REQUEST param. if we do not getting it from there we try
// the arg(3) if we are on a add form. Also if we are on an add form we know that
// we are a child page.
if (isset($_REQUEST['build_cache_id']) && ($cid = $_REQUEST['build_cache_id']) || arg(1) == 'add' && ($cid = arg(3)) && ($child = TRUE)) {
$cache = cache_get($cid);
nodeconnect_include_form();
if ($child) {
$form_state['#nodeconnect_child_form'] = $cache;
}
if (isset($_REQUEST['return'])) {
unset($_REQUEST['build_cache_id']);
nodeconnect_return_node_form_alter($form, $form_state, $form_id, $cid, $cache);
}
}
// If this for is a child form lets add alter for that purpose
// Note that we are doing this here becuase when we retrun to a form it gets rebuild
// so this will get cuaght in the rebuild
if (isset($form_state['#nodeconnect_child_form'])) {
$cache = $form_state['#nodeconnect_child_form'];
module_load_include('inc', 'nodeconnect', 'nodeconnect.form');
nodeconnect_child_node_form_alter($form, $form_state, $form_id, $cache->cid, $cache);
}
}
/**
* _nodeconnect_get_ref_fields is a helper function to retieve all node_reference_fields
*/
function _nodeconnect_get_ref_fields() {
$ref_fields = array();
foreach (field_info_fields() as $id => $field) {
if ($field['type'] == 'node_reference') {
$ref_fields[$id] = $field;
}
}
return $ref_fields;
}
Functions
Name![]() |
Description |
---|---|
nodeconnect_field_attach_form | Implements hook_field_attache_form(). |
nodeconnect_form_node_form_alter | Implements hook_form_node_form_alter() |
nodeconnect_include_form | Includes the form inc file |
nodeconnect_menu | Implements hook_menu(). |
_nodeconnect_get_ref_fields | _nodeconnect_get_ref_fields is a helper function to retieve all node_reference_fields |