Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

cdm-dataportal / 5.x / modules / expertsdb / noderef_parent.module @ 36311992

History | View | Annotate | Download (2.92 KB)

1
<?php
2
// $Id noderef_parent.module, v 1.0 2007, Andreas Kohlbecker - http://www.bgbm.org/BioDivInf/default.htm $
3

    
4
/**
5
 * @file
6
 * A online information service on  taxonomic experts, their expertise
7
 * and ongoing and planned taxonomic research projects.
8
 * This module is brought to you by the European Distributed Institute of Taxonomy - EDIT
9
 *
10
 * @author Berlin, BGBM, Andreas Kohlbecker 2007 - http://www.bgbm.org/BioDivInf/default.htm
11
 */
12

    
13

    
14
/**
15
 * Implementation of hook_help
16
 */
17
function noderef_parent_help($section='')
18
{
19
	$output = '';
20
	switch ($section)
21
	{
22
		case "admin/help#noderef_add":
23
			$output = '<p>'.t("Node Reference widget not editable but filled with default data.").'</p>';
24
			break;
25
	}
26
	return $output;
27
}
28

    
29
/**
30
 *  Implementation of hook_field_settings().
31
 *
32
 */
33
function noderef_parent_field_settings($op, $field) {
34

    
35
	switch ($op) {
36

    
37
		case 'arguments':
38
			return;
39
	}
40
}
41

    
42
/**
43
 * Implementation of hook_widget_info.
44
 * Specifies the label and that it is a widget for the nodereference field type
45
 */
46
function  noderef_parent_widget_info()
47
{
48
	return array(
49
    'noderef_parent_display' => array(
50
        'label' => 'Node Reference Parent Display',
51
        'field types' => array('nodereference'),
52
	),
53
	);
54
}
55

    
56
/**
57
 * Implementation of hook_widget
58
 */
59
function noderef_parent_widget($op, &$node, $field, &$items)
60
{
61

    
62
	if ($field['widget']['type'] == 'noderef_parent_display')
63
	{
64
		switch ($op) {
65

    
66
			case 'prepare form values':
67

    
68
				if (count($items) == 0 || (count($items)>0 && empty($items['parent_node']) && empty($items[0]['nid']))) {
69
					// must be a new node to be created get the parents node id from the URI parameters
70
					if ( is_numeric($_GET[$field['field_name']]) ) {
71
						$items['default nids'] = array($_GET[$field['field_name']]);
72
					}
73
				}
74
				else {
75
					// node already exists -> get nids from items
76
					$node_field_transposed = content_transpose_array_rows_cols($items);
77
					$items['default nids'] = (array)$node_field_transposed['nid'];
78
				}
79
				break;
80

    
81
			case 'form':
82

    
83
				$default_value = '';
84
				if ( isset($items['default nids'][0]) ){
85
					$parent_node = node_load($items['default nids'][0]);
86
					$default_value =  "[$parent_node->nid]: $parent_node->title";
87
				}
88

    
89
				$form = array();
90
				$form[$field['field_name']] = array('#tree' => TRUE);
91
				$form[$field['field_name']]['parent_node'] = array(
92
          '#type' => 'textfield',
93
          '#title' => t($field['widget']['label']),
94
          '#default_value' => $default_value,
95
          '#disabled' => 'disabled',
96
          '#attributes' => array (
97
            'class' => 'noderef_parent_display',
98
				)
99
				);
100

    
101
				return $form;
102
				break;
103

    
104
			case 'process form values':
105
				preg_match('/^\[(\d+)\].*$/', $items['parent_node'], $matches);
106
				if (!empty($matches)) {
107
					$items[0]['nid'] = $matches[1];
108
				}
109
				// Remove the widget's data representation avoiding attempts to save it.
110
				//unset($items['parent_node']);
111
				$items['parent_node'] = array();
112
				break;
113
		}
114
	}
115
}
Add picture from clipboard (Maximum size: 40 MB)