1 | <?php |
---|
2 | // $Id: theme.inc,v 1.1.2.13 2009/04/28 23:06:37 yched Exp $ |
---|
3 | |
---|
4 | /** |
---|
5 | * @file |
---|
6 | * Theme preprocess function for content-admin-field-overview-form.tpl.php. |
---|
7 | */ |
---|
8 | function template_preprocess_content_field_overview_form(&$vars) { |
---|
9 | $form = &$vars['form']; |
---|
10 | |
---|
11 | $vars['help'] = theme('advanced_help_topic', 'content', 'manage-fields') . t('Add fields and groups to the content type, and arrange them on content display and input forms.'); |
---|
12 | if (module_exists('fieldgroup')) { |
---|
13 | $vars['help'] .= '<br/>'. t('You can add a field to a group by dragging it below and to the right of the group.'); |
---|
14 | } |
---|
15 | if (!module_exists('advanced_help')) { |
---|
16 | $vars['help'] .= '<br/>' . t('Note: Installing the <a href="!adv_help">Advanced help</a> module will let you access more and better help.', array('!adv_help' => 'http://drupal.org/project/advanced_help')); |
---|
17 | } |
---|
18 | |
---|
19 | $order = _content_overview_order($form, $form['#field_rows'], $form['#group_rows']); |
---|
20 | $rows = array(); |
---|
21 | |
---|
22 | // Identify the 'new item' keys in the form, they look like |
---|
23 | // _add_new_field, add_new_group. |
---|
24 | $keys = array_keys($form); |
---|
25 | $add_rows = array(); |
---|
26 | foreach ($keys as $key) { |
---|
27 | if (substr($key, 0, 4) == '_add') { |
---|
28 | $add_rows[] = $key; |
---|
29 | } |
---|
30 | } |
---|
31 | while ($order) { |
---|
32 | $key = reset($order); |
---|
33 | $element = &$form[$key]; |
---|
34 | |
---|
35 | // Only display the 'Add' separator if the 'add' rows are still |
---|
36 | // at the end of the table. |
---|
37 | if (!isset($added_separator)) { |
---|
38 | $remaining_rows = array_diff($order, $add_rows); |
---|
39 | if (empty($remaining_rows) && empty($element['#depth'])) { |
---|
40 | $row = new stdClass(); |
---|
41 | $row->row_type = 'separator'; |
---|
42 | $row->class = 'tabledrag-leaf region'; |
---|
43 | $rows[] = $row; |
---|
44 | $added_separator = TRUE; |
---|
45 | } |
---|
46 | } |
---|
47 | |
---|
48 | $row = new stdClass(); |
---|
49 | |
---|
50 | // Add target classes for the tabledrag behavior. |
---|
51 | $element['weight']['#attributes']['class'] = 'field-weight'; |
---|
52 | $element['parent']['#attributes']['class'] = 'group-parent'; |
---|
53 | $element['hidden_name']['#attributes']['class'] = 'field-name'; |
---|
54 | // Add target classes for the update selects behavior. |
---|
55 | switch ($element['#row_type']) { |
---|
56 | case 'add_new_field': |
---|
57 | $element['type']['#attributes']['class'] = 'content-field-type-select'; |
---|
58 | $element['widget_type']['#attributes']['class'] = 'content-widget-type-select'; |
---|
59 | break; |
---|
60 | case 'add_existing_field': |
---|
61 | $element['field_name']['#attributes']['class'] = 'content-field-select'; |
---|
62 | $element['widget_type']['#attributes']['class'] = 'content-widget-type-select'; |
---|
63 | $element['label']['#attributes']['class'] = 'content-label-textfield'; |
---|
64 | break; |
---|
65 | } |
---|
66 | foreach (element_children($element) as $child) { |
---|
67 | $row->{$child} = drupal_render($element[$child]); |
---|
68 | } |
---|
69 | $row->label_class = 'label-'. strtr($element['#row_type'], '_', '-'); |
---|
70 | $row->row_type = $element['#row_type']; |
---|
71 | $row->indentation = theme('indentation', isset($element['#depth']) ? $element['#depth'] : 0); |
---|
72 | $row->class = 'draggable'; |
---|
73 | $row->class .= isset($element['#disabled_row']) ? ' menu-disabled' : ''; |
---|
74 | $row->class .= isset($element['#add_new']) ? ' content-add-new' : ''; |
---|
75 | $row->class .= isset($element['#leaf']) ? ' tabledrag-leaf' : ''; |
---|
76 | $row->class .= isset($element['#root']) ? ' tabledrag-root' : ''; |
---|
77 | |
---|
78 | $rows[] = $row; |
---|
79 | array_shift($order); |
---|
80 | } |
---|
81 | $vars['rows'] = $rows; |
---|
82 | $vars['submit'] = drupal_render($form); |
---|
83 | |
---|
84 | // Add tabledrag behavior. |
---|
85 | // drupal_add_tabledrag('content-field-overview', 'match', 'parent', 'group-parent', 'group-parent', 'field-name', FALSE, 1); |
---|
86 | drupal_add_tabledrag('content-field-overview', 'match', 'parent', 'group-parent', 'group-parent', 'field-name', TRUE, 1); |
---|
87 | // drupal_add_tabledrag('content-field-overview', 'order', 'sibling', 'field-weight', NULL, NULL, FALSE); |
---|
88 | drupal_add_tabledrag('content-field-overview', 'order', 'sibling', 'field-weight'); |
---|
89 | |
---|
90 | // Add settings for the update selects behavior. |
---|
91 | $js_fields = array(); |
---|
92 | foreach (array_keys(content_existing_field_options($form['#type_name'])) as $field_name) { |
---|
93 | $field = content_fields($field_name); |
---|
94 | $js_fields[$field_name] = array('label' => $field['widget']['label'], 'type' => $field['type'], 'widget' => $field['widget']['type']); |
---|
95 | } |
---|
96 | drupal_add_js(array('contentWidgetTypes' => content_widget_type_options(), 'contentFields' => $js_fields), 'setting'); |
---|
97 | drupal_add_js(drupal_get_path('module', 'content') .'/content.js'); |
---|
98 | } |
---|
99 | |
---|
100 | /** |
---|
101 | * Theme preprocess function for content-admin-display-overview-form.tpl.php. |
---|
102 | */ |
---|
103 | function template_preprocess_content_display_overview_form(&$vars) { |
---|
104 | $form = &$vars['form']; |
---|
105 | |
---|
106 | $contexts_selector = $form['#contexts']; |
---|
107 | $vars['basic'] = $contexts_selector == 'basic'; |
---|
108 | $vars['contexts'] = content_build_modes($contexts_selector); |
---|
109 | |
---|
110 | if ($contexts_selector == 'basic') { |
---|
111 | $help = t("Configure how this content type's fields and field labels should be displayed when it's viewed in teaser and full-page mode."); |
---|
112 | } |
---|
113 | else { |
---|
114 | $help = t("Configure how this content type's fields should be displayed when it's rendered in the following contexts."); |
---|
115 | } |
---|
116 | $help .= ' '. t("Use the 'Exclude' checkbox to exclude an item from the !content value passed to the node template.", array('!content' => '$content')); |
---|
117 | $vars['help'] = $help; |
---|
118 | |
---|
119 | $order = _content_overview_order($form, $form['#fields'], $form['#groups']); |
---|
120 | if (empty($order)) { |
---|
121 | $vars['rows'] = array(); |
---|
122 | $vars['submit'] = ''; |
---|
123 | return; |
---|
124 | } |
---|
125 | |
---|
126 | $rows = array(); |
---|
127 | foreach ($order as $key) { |
---|
128 | $element = &$form[$key]; |
---|
129 | $row = new stdClass(); |
---|
130 | foreach (element_children($element) as $child) { |
---|
131 | if (!array_key_exists('exclude', $element[$child])) { |
---|
132 | $row->{$child} = drupal_render($element[$child]); |
---|
133 | } |
---|
134 | else { |
---|
135 | $row->{$child}->format = drupal_render($element[$child]['format']); |
---|
136 | $row->{$child}->exclude = drupal_render($element[$child]['exclude']); |
---|
137 | } |
---|
138 | } |
---|
139 | $row->label_class = in_array($key, $form['#groups']) ? 'label-group' : 'label-field'; |
---|
140 | $row->indentation = theme('indentation', isset($element['#depth']) ? $element['#depth'] : 0); |
---|
141 | $rows[] = $row; |
---|
142 | } |
---|
143 | $vars['rows'] = $rows; |
---|
144 | $vars['submit'] = drupal_render($form); |
---|
145 | } |
---|