Mercurial > hg > rr-repo
comparison modules/field_ui/field_ui.api.php @ 0:ff03f76ab3fe
initial version
author | danieleb <danielebarchiesi@me.com> |
---|---|
date | Wed, 21 Aug 2013 18:51:11 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:ff03f76ab3fe |
---|---|
1 <?php | |
2 | |
3 /** | |
4 * @file | |
5 * Hooks provided by the Field UI module. | |
6 */ | |
7 | |
8 /** | |
9 * @addtogroup field_types | |
10 * @{ | |
11 */ | |
12 | |
13 /** | |
14 * Add settings to a field settings form. | |
15 * | |
16 * Invoked from field_ui_field_settings_form() to allow the module defining the | |
17 * field to add global settings (i.e. settings that do not depend on the bundle | |
18 * or instance) to the field settings form. If the field already has data, only | |
19 * include settings that are safe to change. | |
20 * | |
21 * @todo: Only the field type module knows which settings will affect the | |
22 * field's schema, but only the field storage module knows what schema | |
23 * changes are permitted once a field already has data. Probably we need an | |
24 * easy way for a field type module to ask whether an update to a new schema | |
25 * will be allowed without having to build up a fake $prior_field structure | |
26 * for hook_field_update_forbid(). | |
27 * | |
28 * @param $field | |
29 * The field structure being configured. | |
30 * @param $instance | |
31 * The instance structure being configured. | |
32 * @param $has_data | |
33 * TRUE if the field already has data, FALSE if not. | |
34 * | |
35 * @return | |
36 * The form definition for the field settings. | |
37 */ | |
38 function hook_field_settings_form($field, $instance, $has_data) { | |
39 $settings = $field['settings']; | |
40 $form['max_length'] = array( | |
41 '#type' => 'textfield', | |
42 '#title' => t('Maximum length'), | |
43 '#default_value' => $settings['max_length'], | |
44 '#required' => FALSE, | |
45 '#element_validate' => array('element_validate_integer_positive'), | |
46 '#description' => t('The maximum length of the field in characters. Leave blank for an unlimited size.'), | |
47 ); | |
48 return $form; | |
49 } | |
50 | |
51 /** | |
52 * Add settings to an instance field settings form. | |
53 * | |
54 * Invoked from field_ui_field_edit_form() to allow the module defining the | |
55 * field to add settings for a field instance. | |
56 * | |
57 * @param $field | |
58 * The field structure being configured. | |
59 * @param $instance | |
60 * The instance structure being configured. | |
61 * | |
62 * @return | |
63 * The form definition for the field instance settings. | |
64 */ | |
65 function hook_field_instance_settings_form($field, $instance) { | |
66 $settings = $instance['settings']; | |
67 | |
68 $form['text_processing'] = array( | |
69 '#type' => 'radios', | |
70 '#title' => t('Text processing'), | |
71 '#default_value' => $settings['text_processing'], | |
72 '#options' => array( | |
73 t('Plain text'), | |
74 t('Filtered text (user selects text format)'), | |
75 ), | |
76 ); | |
77 if ($field['type'] == 'text_with_summary') { | |
78 $form['display_summary'] = array( | |
79 '#type' => 'select', | |
80 '#title' => t('Display summary'), | |
81 '#options' => array( | |
82 t('No'), | |
83 t('Yes'), | |
84 ), | |
85 '#description' => t('Display the summary to allow the user to input a summary value. Hide the summary to automatically fill it with a trimmed portion from the main post.'), | |
86 '#default_value' => !empty($settings['display_summary']) ? $settings['display_summary'] : 0, | |
87 ); | |
88 } | |
89 | |
90 return $form; | |
91 } | |
92 | |
93 /** | |
94 * Add settings to a widget settings form. | |
95 * | |
96 * Invoked from field_ui_field_edit_form() to allow the module defining the | |
97 * widget to add settings for a widget instance. | |
98 * | |
99 * @param $field | |
100 * The field structure being configured. | |
101 * @param $instance | |
102 * The instance structure being configured. | |
103 * | |
104 * @return | |
105 * The form definition for the widget settings. | |
106 */ | |
107 function hook_field_widget_settings_form($field, $instance) { | |
108 $widget = $instance['widget']; | |
109 $settings = $widget['settings']; | |
110 | |
111 if ($widget['type'] == 'text_textfield') { | |
112 $form['size'] = array( | |
113 '#type' => 'textfield', | |
114 '#title' => t('Size of textfield'), | |
115 '#default_value' => $settings['size'], | |
116 '#element_validate' => array('element_validate_integer_positive'), | |
117 '#required' => TRUE, | |
118 ); | |
119 } | |
120 else { | |
121 $form['rows'] = array( | |
122 '#type' => 'textfield', | |
123 '#title' => t('Rows'), | |
124 '#default_value' => $settings['rows'], | |
125 '#element_validate' => array('element_validate_integer_positive'), | |
126 '#required' => TRUE, | |
127 ); | |
128 } | |
129 | |
130 return $form; | |
131 } | |
132 | |
133 | |
134 /** | |
135 * Specify the form elements for a formatter's settings. | |
136 * | |
137 * @param $field | |
138 * The field structure being configured. | |
139 * @param $instance | |
140 * The instance structure being configured. | |
141 * @param $view_mode | |
142 * The view mode being configured. | |
143 * @param $form | |
144 * The (entire) configuration form array, which will usually have no use here. | |
145 * @param $form_state | |
146 * The form state of the (entire) configuration form. | |
147 * | |
148 * @return | |
149 * The form elements for the formatter settings. | |
150 */ | |
151 function hook_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) { | |
152 $display = $instance['display'][$view_mode]; | |
153 $settings = $display['settings']; | |
154 | |
155 $element = array(); | |
156 | |
157 if ($display['type'] == 'text_trimmed' || $display['type'] == 'text_summary_or_trimmed') { | |
158 $element['trim_length'] = array( | |
159 '#title' => t('Length'), | |
160 '#type' => 'textfield', | |
161 '#size' => 20, | |
162 '#default_value' => $settings['trim_length'], | |
163 '#element_validate' => array('element_validate_integer_positive'), | |
164 '#required' => TRUE, | |
165 ); | |
166 } | |
167 | |
168 return $element; | |
169 | |
170 } | |
171 | |
172 /** | |
173 * Return a short summary for the current formatter settings of an instance. | |
174 * | |
175 * If an empty result is returned, the formatter is assumed to have no | |
176 * configurable settings, and no UI will be provided to display a settings | |
177 * form. | |
178 * | |
179 * @param $field | |
180 * The field structure. | |
181 * @param $instance | |
182 * The instance structure. | |
183 * @param $view_mode | |
184 * The view mode for which a settings summary is requested. | |
185 * | |
186 * @return | |
187 * A string containing a short summary of the formatter settings. | |
188 */ | |
189 function hook_field_formatter_settings_summary($field, $instance, $view_mode) { | |
190 $display = $instance['display'][$view_mode]; | |
191 $settings = $display['settings']; | |
192 | |
193 $summary = ''; | |
194 | |
195 if ($display['type'] == 'text_trimmed' || $display['type'] == 'text_summary_or_trimmed') { | |
196 $summary = t('Length: @chars chars', array('@chars' => $settings['trim_length'])); | |
197 } | |
198 | |
199 return $summary; | |
200 } | |
201 | |
202 /** | |
203 * @} End of "addtogroup field_types". | |
204 */ |