| 1 |
<?php
|
| 2 |
// $Id: theme.inc,v 1.7 2009/02/07 01:09:36 yched Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Theme preprocess function for cck-admin-field-overview-form.tpl.php.
|
| 7 |
*/
|
| 8 |
function template_preprocess_cck_field_overview_form(&$vars) {
|
| 9 |
$form = &$vars['form'];
|
| 10 |
|
| 11 |
// TODO D7: abstract texts over bundles / entity types
|
| 12 |
switch ($form['#bundle']) {
|
| 13 |
case 'user':
|
| 14 |
$vars['help'] = theme('advanced_help_topic', 'cck', 'manage-user-fields') . t('Add fields to the user, and arrange them on user display and input forms.');
|
| 15 |
break;
|
| 16 |
default:
|
| 17 |
$vars['help'] = theme('advanced_help_topic', 'cck', 'manage-fields') . t('Add fields to the Content type, and arrange them on content display and input forms.');
|
| 18 |
}
|
| 19 |
if (module_exists('fieldgroup')) {
|
| 20 |
$vars['help'] .= '<br>'. t('You can add a field to a group by dragging it below and to the right of the group.');
|
| 21 |
}
|
| 22 |
if (!module_exists('advanced_help')) {
|
| 23 |
// TODO D7
|
| 24 |
//$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'));
|
| 25 |
}
|
| 26 |
|
| 27 |
$order = _cck_overview_order($form, $form['#field_rows'], $form['#group_rows']);
|
| 28 |
$rows = array();
|
| 29 |
|
| 30 |
// Identify the 'new item' keys in the form, they look like
|
| 31 |
// _add_new_field, add_new_group.
|
| 32 |
$keys = array_keys($form);
|
| 33 |
$add_rows = array();
|
| 34 |
foreach ($keys as $key) {
|
| 35 |
if (substr($key, 0, 4) == '_add') {
|
| 36 |
$add_rows[] = $key;
|
| 37 |
}
|
| 38 |
}
|
| 39 |
while ($order) {
|
| 40 |
$key = reset($order);
|
| 41 |
$element = &$form[$key];
|
| 42 |
|
| 43 |
// Only display the 'Add' separator if the 'add' rows are still
|
| 44 |
// at the end of the table.
|
| 45 |
if (!isset($added_separator)) {
|
| 46 |
$remaining_rows = array_diff($order, $add_rows);
|
| 47 |
if (empty($remaining_rows) && empty($element['#depth'])) {
|
| 48 |
$row = new stdClass();
|
| 49 |
$row->row_type = 'separator';
|
| 50 |
$row->class = 'tabledrag-leaf region';
|
| 51 |
$rows[] = $row;
|
| 52 |
$added_separator = TRUE;
|
| 53 |
}
|
| 54 |
}
|
| 55 |
|
| 56 |
$row = new stdClass();
|
| 57 |
|
| 58 |
// Add target classes for the tabledrag behavior.
|
| 59 |
$element['weight']['#attributes']['class'] = 'field-weight';
|
| 60 |
$element['parent']['#attributes']['class'] = 'group-parent';
|
| 61 |
$element['hidden_name']['#attributes']['class'] = 'field-name';
|
| 62 |
// Add target classes for the update selects behavior.
|
| 63 |
switch ($element['#row_type']) {
|
| 64 |
case 'add_new_field':
|
| 65 |
$element['type']['#attributes']['class'] = 'cck-field-type-select';
|
| 66 |
$element['widget_type']['#attributes']['class'] = 'cck-widget-type-select';
|
| 67 |
break;
|
| 68 |
case 'add_existing_field':
|
| 69 |
$element['field_name']['#attributes']['class'] = 'cck-field-select';
|
| 70 |
$element['widget_type']['#attributes']['class'] = 'cck-widget-type-select';
|
| 71 |
$element['label']['#attributes']['class'] = 'cck-label-textfield';
|
| 72 |
break;
|
| 73 |
}
|
| 74 |
foreach (element_children($element) as $child) {
|
| 75 |
$row->{$child} = drupal_render($element[$child]);
|
| 76 |
}
|
| 77 |
$row->label_class = 'label-'. strtr($element['#row_type'], '_', '-');
|
| 78 |
$row->row_type = $element['#row_type'];
|
| 79 |
$row->indentation = theme('indentation', isset($element['#depth']) ? $element['#depth'] : 0);
|
| 80 |
$row->class = 'draggable';
|
| 81 |
$row->class .= isset($element['#disabled_row']) ? ' menu-disabled' : '';
|
| 82 |
$row->class .= isset($element['#add_new']) ? ' cck-add-new' : '';
|
| 83 |
$row->class .= isset($element['#leaf']) ? ' tabledrag-leaf' : '';
|
| 84 |
$row->class .= isset($element['#root']) ? ' tabledrag-root' : '';
|
| 85 |
|
| 86 |
$rows[] = $row;
|
| 87 |
array_shift($order);
|
| 88 |
}
|
| 89 |
$vars['rows'] = $rows;
|
| 90 |
$vars['submit'] = drupal_render_children($form);
|
| 91 |
|
| 92 |
// Add tabledrag behavior.
|
| 93 |
drupal_add_tabledrag('cck-field-overview', 'match', 'parent', 'group-parent', 'group-parent', 'field-name', TRUE, 1);
|
| 94 |
drupal_add_tabledrag('cck-field-overview', 'order', 'sibling', 'field-weight');
|
| 95 |
|
| 96 |
// Add settings for the update selects behavior.
|
| 97 |
// TODO D7 : adapt...
|
| 98 |
$js_fields = array();
|
| 99 |
foreach (cck_existing_field_options($form['#bundle']) as $field_name => $fields) {
|
| 100 |
$field = field_info_field($field_name);
|
| 101 |
$instance = field_info_instance($field_name, $form['#bundle']);
|
| 102 |
$js_fields[$field_name] = array('label' => $instance['label'], 'type' => $field['type'], 'widget' => $instance['widget']['type']);
|
| 103 |
}
|
| 104 |
drupal_add_js(array('cckWidgetTypes' => cck_widget_type_options(), 'cckFields' => $js_fields), 'setting');
|
| 105 |
drupal_add_js(drupal_get_path('module', 'cck') .'/cck.js');
|
| 106 |
}
|
| 107 |
|
| 108 |
/**
|
| 109 |
* Theme preprocess function for cck-admin-display-overview-form.tpl.php.
|
| 110 |
*/
|
| 111 |
function template_preprocess_cck_display_overview_form(&$vars) {
|
| 112 |
$form = &$vars['form'];
|
| 113 |
|
| 114 |
$contexts_selector = $form['#contexts'];
|
| 115 |
$vars['basic'] = $contexts_selector == 'basic';
|
| 116 |
|
| 117 |
$vars['contexts'] = cck_build_modes(field_info_bundle_entity($form['#bundle']), $contexts_selector);
|
| 118 |
|
| 119 |
// TODO D7: abstract texts over bundles / entity types
|
| 120 |
switch ($form['#bundle']) {
|
| 121 |
case 'user':
|
| 122 |
$help = t('Configure how user fields and field labels should be displayed.');
|
| 123 |
break;
|
| 124 |
|
| 125 |
default:
|
| 126 |
if ($contexts_selector == 'basic') {
|
| 127 |
$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.");
|
| 128 |
}
|
| 129 |
else {
|
| 130 |
$help = t("Configure how this content type's fields should be displayed when it's rendered in the following contexts.");
|
| 131 |
}
|
| 132 |
}
|
| 133 |
|
| 134 |
$vars['help'] = $help;
|
| 135 |
|
| 136 |
$order = _cck_overview_order($form, $form['#fields'], $form['#groups']);
|
| 137 |
if (empty($order)) {
|
| 138 |
$vars['rows'] = array();
|
| 139 |
$vars['submit'] = '';
|
| 140 |
return;
|
| 141 |
}
|
| 142 |
$rows = array();
|
| 143 |
foreach ($order as $key) {
|
| 144 |
$element = &$form[$key];
|
| 145 |
$row = new stdClass();
|
| 146 |
foreach (element_children($element) as $child) {
|
| 147 |
if (array_key_exists('label', $element[$child])) {
|
| 148 |
$row->{$child}->label = drupal_render($element[$child]['label']);
|
| 149 |
$row->{$child}->type = drupal_render($element[$child]['type']);
|
| 150 |
}
|
| 151 |
else {
|
| 152 |
$row->{$child} = drupal_render($element[$child]);
|
| 153 |
}
|
| 154 |
}
|
| 155 |
$row->label_class = in_array($key, $form['#groups']) ? 'label-group' : 'label-field';
|
| 156 |
$row->indentation = theme('indentation', isset($element['#depth']) ? $element['#depth'] : 0);
|
| 157 |
$rows[] = $row;
|
| 158 |
}
|
| 159 |
|
| 160 |
$vars['rows'] = $rows;
|
| 161 |
$vars['submit'] = drupal_render_children($form);
|
| 162 |
}
|