Index: modules/field_ui/field_ui.js
===================================================================
RCS file: /cvs/drupal/drupal/modules/field_ui/field_ui.js,v
retrieving revision 1.1
diff -u -r1.1 field_ui.js
--- modules/field_ui/field_ui.js 19 Aug 2009 13:31:13 -0000 1.1
+++ modules/field_ui/field_ui.js 1 Jan 2010 16:02:57 -0000
@@ -8,6 +8,43 @@
}
};
+Drupal.behaviors.fieldManageDisplaySourceSelect = {
+ attach: function (context, settings) {
+ $('div#modes-wrapper select.view-mode-source')
+ .each(function() {
+ toggleViewMode(this);
+ })
+ .bind('change', function() {
+ toggleViewMode(this, context);
+ });
+ }
+};
+
+function toggleViewMode(viewModeSource, context) {
+ var viewMode = $(viewModeSource, context).parent().parent().find('div.view-mode-wrapper');
+ if ($(viewModeSource, context).val() == '_custom') {
+ viewMode.show();
+ }
+ else {
+ viewMode.hide();
+ }
+}
+
+Drupal.behaviors.fieldManageDisplayFieldsetSummaries = {
+ attach: function (context, settings) {
+ var modes = settings.fieldViewModes;
+ for (var mode in modes) {
+ $('fieldset#edit-modes-' + mode, context).setSummary(function (context) {
+ // Get the value of the 'source' select for the view mode.
+ var value = $('.form-select.view-mode-source option:selected', context).val();
+ return (value == '_custom') ?
+ '' :
+ Drupal.t('Uses @view_mode settings', {'@view_mode': modes[value]});
+ });
+ }
+ }
+};
+
function attachUpdateSelects(context) {
var widgetTypes = Drupal.settings.fieldWidgetTypes;
var fields = Drupal.settings.fields;
Index: modules/field_ui/field_ui.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/field_ui/field_ui.module,v
retrieving revision 1.20
diff -u -r1.20 field_ui.module
--- modules/field_ui/field_ui.module 26 Dec 2009 16:50:08 -0000 1.20
+++ modules/field_ui/field_ui.module 1 Jan 2010 16:02:57 -0000
@@ -108,7 +108,7 @@
'file' => 'field_ui.admin.inc',
) + $access;
- // 'Manage display' tab and context secondary tabs.
+ // 'Manage display' tab.
$items["$path/display"] = array(
'title' => 'Manage display',
'page callback' => 'drupal_get_form',
@@ -117,16 +117,6 @@
'weight' => 2,
'file' => 'field_ui.admin.inc',
) + $access;
- $tabs = field_ui_view_modes_tabs($obj_type);
- foreach ($tabs as $key => $tab) {
- $items["$path/display/$key"] = array(
- 'title' => $tab['title'],
- 'page arguments' => array('field_ui_display_overview_form', $obj_type, $bundle_arg, $key),
- 'type' => $key == 'basic' ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK,
- 'weight' => $key == 'basic' ? 0 : 1,
- 'file' => 'field_ui.admin.inc',
- ) + $access;
- }
}
}
}
@@ -162,87 +152,12 @@
'file' => 'field_ui.admin.inc',
'template' => 'field_ui-field-overview-form',
),
- 'field_ui_display_overview_form' => array(
- 'render element' => 'form',
+ 'field_ui_display_overview_table' => array(
+ 'render element' => 'elements',
'file' => 'field_ui.admin.inc',
- 'template' => 'field_ui-display-overview-form',
- ),
- );
-}
-
-/**
- * Group available view modes on tabs on the 'Manage display' page.
- *
- * @todo Remove this completely and use vertical tabs?
- */
-function field_ui_view_modes_tabs($obj_type, $tab_selector = NULL) {
- $info = &drupal_static(__FUNCTION__);
-
- if (!isset($info[$obj_type])) {
- $info[$obj_type] = module_invoke_all('field_ui_view_modes_tabs', $obj_type);
- // Filter out inactive modes.
- $entity_info = entity_get_info($obj_type);
- foreach ($info[$obj_type] as $tab => $values) {
- $modes = array();
- foreach ($info[$obj_type][$tab]['view modes'] as $mode) {
- if (isset($entity_info['view modes'][$mode])) {
- $modes[] = $mode;
- }
- }
- if ($modes) {
- $info[$obj_type][$tab]['view modes'] = $modes;
- }
- else {
- unset($info[$obj_type][$tab]);
- }
- }
- }
- if ($tab_selector) {
- return isset($info[$obj_type][$tab_selector]) ? $info[$obj_type][$tab_selector]['view modes'] : array();
- }
- return $info[$obj_type];
-}
-
-/**
- * Implements hook_field_ui_view_modes_tabs() on behalf of other core modules.
- *
- * @return
- * An array describing the view modes defined by the module, grouped by tabs.
- *
- * A module can add its render modes to a tab defined by another module.
- * Expected format:
- * @code
- * array(
- * 'tab1' => array(
- * 'title' => t('The human-readable title of the tab'),
- * 'view modes' => array('mymodule_mode1', 'mymodule_mode2'),
- * ),
- * 'tab2' => array(
- * // ...
- * ),
- * );
- * @endcode
- */
-function field_ui_field_ui_view_modes_tabs() {
- $modes = array(
- 'basic' => array(
- 'title' => t('Basic'),
- 'view modes' => array('teaser', 'full'),
- ),
- 'rss' => array(
- 'title' => t('RSS'),
- 'view modes' => array('rss'),
- ),
- 'print' => array(
- 'title' => t('Print'),
- 'view modes' => array('print'),
- ),
- 'search' => array(
- 'title' => t('Search'),
- 'view modes' => array('search_index', 'search_result'),
+ 'template' => 'field_ui-display-overview-table',
),
);
- return $modes;
}
/**
Index: modules/field_ui/field_ui-display-overview-form.tpl.php
===================================================================
RCS file: modules/field_ui/field_ui-display-overview-form.tpl.php
diff -N modules/field_ui/field_ui-display-overview-form.tpl.php
--- modules/field_ui/field_ui-display-overview-form.tpl.php 19 Aug 2009 13:31:13 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,55 +0,0 @@
-
-
-
-
-
- | |
- $value): ?>
-
-
- |
-
- |
- $value): ?>
- |
- |
-
-
-
-
-
-
- | human_name; ?> |
- $title): ?>
- {$context}->label; ?> |
- {$context}->type; ?> |
-
-
-
-
-
-
-
Index: modules/field_ui/field_ui.admin.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/field_ui/field_ui.admin.inc,v
retrieving revision 1.33
diff -u -r1.33 field_ui.admin.inc
--- modules/field_ui/field_ui.admin.inc 26 Dec 2009 16:50:08 -0000 1.33
+++ modules/field_ui/field_ui.admin.inc 1 Jan 2010 16:02:57 -0000
@@ -570,7 +570,7 @@
* This form includes form widgets to select which fields appear in teaser and
* full view modes, and how the field labels should be rendered.
*/
-function field_ui_display_overview_form($form, &$form_state, $obj_type, $bundle, $view_modes_selector = 'basic') {
+function field_ui_display_overview_form($form, &$form_state, $obj_type, $bundle) {
$bundle = field_extract_bundle($obj_type, $bundle);
field_ui_inactive_message($obj_type, $bundle);
@@ -579,14 +579,15 @@
// Gather type information.
$instances = field_info_instances($obj_type, $bundle);
$field_types = field_info_field_types();
- $view_modes = field_ui_view_modes_tabs($obj_type, $view_modes_selector);
+ $entity_info = entity_get_info($obj_type);
+ $view_modes = $entity_info['view modes'];
$form += array(
'#tree' => TRUE,
+ // @todo Needed ?
'#object_type' => $obj_type,
'#bundle' => $bundle,
'#fields' => array_keys($instances),
- '#contexts' => $view_modes_selector,
);
if (empty($instances)) {
@@ -594,83 +595,121 @@
return $form;
}
- // Fields.
+ // Prepare an array of view modes as HTML IDs for the JS script.
+ $view_modes_js = array();
+
+ // Gather view mode options for settings source.
+ $view_modes_options = array(
+ '_custom' => t('Use custom settings.'),
+ );
+ foreach ($view_modes as $view_mode => $view_mode_info) {
+ $view_modes_options[$view_mode] = t('Copy settings from !view_mode', array('!view_mode' => $view_mode_info['label']));
+ }
+
$label_options = array(
'above' => t('Above'),
'inline' => t('Inline'),
'hidden' => t(''),
);
- foreach ($instances as $name => $instance) {
- $field = field_info_field($instance['field_name']);
- $weight = $instance['widget']['weight'];
- $form[$name] = array(
- 'human_name' => array('#markup' => check_plain($instance['label'])),
- 'weight' => array('#type' => 'value', '#value' => $weight),
+ $form['modes'] = array(
+ '#type' => 'container',
+ '#weight' => 1,
+ );
+
+ foreach ($view_modes as $view_mode => $view_mode_info) {
+ $view_modes_js[drupal_html_class($view_mode)] = $view_mode_info['label'];
+
+ $element = array(
+ '#type' => 'container',
+ '#theme' => 'field_ui_display_overview_table',
+ '#fields' => array_keys($instances),
+ '#attributes' => array('class' => array('view-mode-wrapper')),
);
- $defaults = $instance['display'];
- $formatter_options = field_ui_formatter_options($field['type']);
- $formatter_options['hidden'] = t('');
- foreach ($view_modes as $view_mode) {
+ foreach ($instances as $name => $instance) {
+ $field = field_info_field($instance['field_name']);
+ $weight = $instance['widget']['weight'];
+
+ $element[$name]['human_name'] = array(
+ '#markup' => check_plain($instance['label']),
+ );
+ $element[$name]['weight'] = array(
+ '#type' => 'value',
+ '#value' => $weight,
+ );
+
+ $formatter_options = field_ui_formatter_options($field['type']);
+ $formatter_options['hidden'] = t('');
$display = isset($instance['display'][$view_mode]) ? $instance['display'][$view_mode] : $instance['display']['full'];
- $form[$name][$view_mode]['label'] = array(
+
+ $element[$name]['label'] = array(
'#type' => 'select',
'#options' => $label_options,
'#default_value' => $display['label'],
);
- $form[$name][$view_mode]['type'] = array(
+ $element[$name]['type'] = array(
'#type' => 'select',
'#options' => $formatter_options,
'#default_value' => $display['type'],
);
}
+
+ $form['modes'][$view_mode] = array(
+ '#type' => 'fieldset',
+ '#title' => $view_mode_info['label'],
+ '#collapsible' => TRUE,
+ '#collapsed' => TRUE,
+ );
+
+ // Remove the 'Copy settings' option for the current view mode.
+ $options = $view_modes_options;
+ unset($options[$view_mode]);
+ $form['modes'][$view_mode]['source'] = array(
+ '#type' => 'select',
+ '#title' => t('Settings source'),
+ '#default_value' => 'custom',
+ '#options' => $options,
+ '#attributes' => array('class' => array('view-mode-source')),
+ );
+ $form['modes'][$view_mode]['wrapper'] = $element;
}
- $form['submit'] = array('#type' => 'submit', '#value' => t('Save'));
+ $form['submit'] = array('#type' => 'submit', '#value' => t('Save'), '#weight' => 10);
+
+ $form['#attached']['js'][] = drupal_get_path('module', 'field_ui') . '/field_ui.js';
+ drupal_add_js(array('fieldViewModes' => $view_modes_js), 'setting');
+
return $form;
}
/**
* Theme preprocess function for field_ui-display-overview-form.tpl.php.
*/
-function template_preprocess_field_ui_display_overview_form(&$vars) {
- $form = &$vars['form'];
+function template_preprocess_field_ui_display_overview_table(&$vars) {
+ $elements = &$vars['elements'];
- $contexts_selector = $form['#contexts'];
- $view_modes = field_ui_view_modes_tabs($form['#object_type'], $contexts_selector);
- $entity_info = entity_get_info($form['#object_type']);
- $view_modes_info = $entity_info['view modes'];
- $vars['contexts'] = array();
- foreach ($view_modes as $view_mode) {
- $vars['contexts'][$view_mode] = $view_modes_info[$view_mode]['label'];
- }
-
- $order = _field_ui_overview_order($form, $form['#fields']);
- if (empty($order)) {
- $vars['rows'] = array();
- $vars['submit'] = '';
- return;
- }
$rows = array();
- foreach ($order as $key) {
- $element = &$form[$key];
- $row = new stdClass();
- foreach (element_children($element) as $child) {
- if (array_key_exists('label', $element[$child])) {
- $row->{$child}->label = drupal_render($element[$child]['label']);
- $row->{$child}->type = drupal_render($element[$child]['type']);
- }
- else {
- $row->{$child} = drupal_render($element[$child]);
+ if (!empty($elements['#fields'])) {
+ $order = _field_ui_overview_order($elements, $elements['#fields']);
+ foreach ($order as $key) {
+ $element = &$elements[$key];
+ $row = new stdClass();
+ foreach (element_children($element) as $child) {
+ if (array_key_exists('label', $element[$child])) {
+ $row->{$child}->label = drupal_render($element[$child]['label']);
+ $row->{$child}->type = drupal_render($element[$child]['type']);
+ }
+ else {
+ $row->{$child} = drupal_render($element[$child]);
+ }
}
+ $row->label_class = 'label-field';
+ $rows[] = $row;
}
- $row->label_class = 'label-field';
- $rows[] = $row;
}
$vars['rows'] = $rows;
- $vars['submit'] = drupal_render_children($form);
}
/**
Index: modules/field_ui/field_ui-display-overview-table.tpl.php
===================================================================
RCS file: modules/field_ui/field_ui-display-overview-table.tpl.php
diff -N modules/field_ui/field_ui-display-overview-table.tpl.php
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ modules/field_ui/field_ui-display-overview-table.tpl.php 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,38 @@
+
+
+
+
+
+ |
+ |
+ |
+
+
+
+
+
+ | human_name; ?> |
+ label; ?> |
+ type; ?> |
+
+
+
+
+