diff --git a/field_group.api.php b/field_group.api.php index 38abcc0..2220cd0 100644 --- a/field_group.api.php +++ b/field_group.api.php @@ -17,7 +17,7 @@ * This is done to be sure fieldgroup is not taking fieldsets from profile2, commerce line items, * commerce user profiles, ... . * When trying to merge a programmatically created field wrapper (div, markup, fieldset, ...) into - * groups, you might consider adding it in #field_groups as well if you want the element processed + * groups, you might consider adding it in #fieldgroups as well if you want the element processed * by fieldgroup. */ @@ -384,19 +384,6 @@ function hook_field_group_format_settings_alter(&$form, &$group) { // Alter the group format settings that appear in the summary and form. } -/** - * Implements hook_field_group_field_ui_parent_requirements_alter(). - * - * @param array $parent_requirements - * An associative array keyed by group type of a group parent. - * @param array $context - * Array of the form structure and display overview. - */ -function hook_field_group_field_ui_parent_requirements_alter(&$parent_requirements, &$context) { - // Alter the parent requirements array used to display warning if a container - // has not been set up. -} - /** * Implements hook_field_group_html_classes_alter(). * diff --git a/field_group.field_ui.inc b/field_group.field_ui.inc index b7d8641..a75bc0b 100644 --- a/field_group.field_ui.inc +++ b/field_group.field_ui.inc @@ -71,10 +71,6 @@ function field_group_field_ui_overview_form_alter(&$form, &$form_state, $display // Add some things to be able to preserve synced usage of field_ui. if (!$display_overview) { - // This key is used to store the current updated field. - $form_state += array( - 'formatter_settings_edit' => NULL, - ); // Add AJAX wrapper. $form['fields']['#prefix'] = '
'; $form['fields']['#suffix'] = '
'; @@ -127,10 +123,6 @@ function field_group_field_ui_overview_form_alter(&$form, &$form_state, $display // This needs to be done first, so all fields are updated before creating form elements. if (isset($refresh_rows) && $refresh_rows == $name) { $settings = isset($form_state['values']['fields'][$name]) ? $form_state['values']['fields'][$name] : (isset($form_state['input']['fields'][$name]) ? $form_state['input']['fields'][$name] : NULL); - if (array_key_exists('settings_edit', $settings)) { - //$group->format_type = $form_state['field_group'][$name]->format_type; - $group = $form_state['field_group'][$name]; - } field_group_formatter_row_update($group, $settings); } @@ -141,8 +133,6 @@ function field_group_field_ui_overview_form_alter(&$form, &$form_state, $display // After all updates are finished, let the form_state know. $form_state['field_group'][$name] = $group; - $settings = field_group_format_settings_form($group); - $id = strtr($name, '_', '-'); $js_rows_data[$id] = array('type' => 'group', 'name' => $name); // A group cannot be selected as its own parent. @@ -195,81 +185,39 @@ function field_group_field_ui_overview_form_alter(&$form, &$form_state, $display ), ); - $base_button = array( - '#submit' => array('field_ui_display_overview_multistep_submit'), - '#ajax' => array( - 'callback' => 'field_ui_display_overview_multistep_js', - 'wrapper' => 'field-display-overview-wrapper', - 'effect' => 'fade', + // After saving, the settings are updated here as well. First we create + // the element for the table cell. + $table[$name]['settings_summary'] = array('#markup' => ''); + if (!empty($group->format_settings)) { + $table[$name]['settings_summary'] = field_group_format_settings_summary($name, $group); + } + + $destination = _field_ui_bundle_admin_path($form['#entity_type'], $form['#bundle']); + $operations = array( + 'configure' => array( + 'title' => t('Configure'), + 'href' => $params->admin_path . '/groups/' . $name . '/configure/form', + 'query' => array('destination' => $destination . '/fields'), + ), + 'delete' => array( + 'title' => t('Delete'), + 'href' => $params->admin_path . '/groups/' . $name . '/delete/form', + 'query' => array('destination' => $destination . '/fields'), ), - '#field_name' => $name, ); - - if ($form_state['formatter_settings_edit'] == $name) { - $table[$name]['format']['#cell_attributes'] = array('colspan' => $display_overview ? 3 : 2); - $table[$name]['format']['format_settings'] = array( - '#type' => 'container', - '#attributes' => array('class' => array('field-formatter-settings-edit-form')), - '#parents' => array('fields', $name, 'format_settings'), - '#weight' => -5, - 'label' => array( - '#markup' => t('Field group format:') . ' ' . $group->format_type . '', - ), - // Create a settings form where hooks can pick in. - 'settings' => $settings, - 'actions' => array( - '#type' => 'actions', - 'save_settings' => $base_button + array( - '#type' => 'submit', - '#name' => $name . '_formatter_settings_update', - '#value' => t('Update'), - '#op' => 'update', - ), - 'cancel_settings' => $base_button + array( - '#type' => 'submit', - '#name' => $name . '_formatter_settings_cancel', - '#value' => t('Cancel'), - '#op' => 'cancel', - // Do not check errors for the 'Cancel' button. - '#limit_validation_errors' => array(), - ), - ), - ); - $table[$name]['#attributes']['class'][] = 'field-formatter-settings-editing'; - $table[$name]['format']['type']['#attributes']['class'] = array('element-invisible'); - } - else { - // After saving, the settings are updated here as well. First we create - // the element for the table cell. - $table[$name]['settings_summary'] = array('#markup' => ''); - if (!empty($group->format_settings)) { - $table[$name]['settings_summary'] = field_group_format_settings_summary($name, $group); - } - // Add the configure button. - $table[$name]['settings_edit'] = array( - '#type' => 'container', - '#attributes' => array('class' => array('field-formatter-settings-edit-wrapper')), - ); - $table[$name]['settings_edit']['edit'] = $base_button + array( - '#type' => 'submit', - '#name' => $name . '_group_settings_edit', - '#value' => t('Configure'), - '#attributes' => array('class' => array('field-formatter-settings-edit button-secondary'), 'alt' => t('Configure')), - '#op' => 'edit', - // Do not check errors for the 'Configure' button. - '#limit_validation_errors' => array(), - ); - if ($display_overview) { - $table[$name]['settings_edit']['delete'] = array( - '#markup' => l(t('Delete'), $params->admin_path . '/groups/' . $name . '/delete/' . $params->mode), - ); - } - } - if (!$display_overview) { - $table[$name]['settings_edit']['delete'] = array( - '#markup' => l(t('Delete'), $params->admin_path . '/groups/' . $name . '/delete/form'), - ); + if ($display_overview) { + $operations['configure']['href'] = $params->admin_path . '/groups/' . $name . '/configure/' . $params->mode; + $operations['configure']['query']['destination'] = $destination . '/display/' . $params->mode; + $operations['delete']['href'] = $params->admin_path . '/groups/' . $name . '/delete/' . $params->mode; + $operations['delete']['query']['destination'] = $destination . '/display/' . $params->mode; } + + // Add the operations. + $table[$name]['operations'] = array( + '#type' => 'dropbutton', + '#links' => $operations, + ); + } // Additional row: add new group. @@ -475,18 +423,16 @@ function field_group_format_settings_form(&$group) { * An associative array containing the current state of the form. */ function field_group_format_settings_label_validate($element, &$form_state) { + $values = $form_state['values']; + + $group = $form_state['complete_form']['#group']; - $group = $form_state['values']['fields'][$element['#parents'][1]]; - $settings = $group['format_settings']['settings']; - $name = $form_state['formatter_settings_edit']; - $form_state['values']['fields'][$name]['settings_edit_form']['settings'] = $settings; - if ($group['format']['type'] == 'fieldset' && ($settings['formatter'] == 'collapsed' || $settings['formatter'] == 'collapsible') && empty($settings['label'])) { + if ($group->format_type == 'fieldset' && ($values['formatter'] == 'collapsed' || $values['formatter'] == 'collapsible') && empty($values['label'])) { form_error($element, t('The label is required when formatter is collapsible or collapsed')); } - if ($group['format']['type'] == 'details' && empty($settings['label'])) { + if ($group->format_type == 'details' && empty($values['label'])) { form_error($element, t('The label is required')); } - } /** @@ -771,7 +717,7 @@ function field_group_field_overview_submit($form, &$form_state) { * The state of the form. */ function field_group_validate_css_class($element, &$form_state) { - if (!empty($form_state['values']['fields'][$form_state['formatter_settings_edit']]['format_settings']['settings']['instance_settings']['classes']) && !preg_match('!^[A-Za-z0-9-_ ]+$!', $form_state['values']['fields'][$form_state['formatter_settings_edit']]['format_settings']['settings']['instance_settings']['classes'])) { + if (!empty($form_state['values']['instance_settings']['classes']) && !preg_match('!^[A-Za-z0-9-_ ]+$!', $form_state['values']['instance_settings']['classes'])) { form_error($element, t('The css class must include only letters, numbers, underscores and dashes.')); } } @@ -785,7 +731,7 @@ function field_group_validate_css_class($element, &$form_state) { * The state of the form. */ function field_group_validate_id($element, &$form_state) { - if (!empty($form_state['values']['fields'][$form_state['formatter_settings_edit']]['format_settings']['settings']['instance_settings']['id']) && !preg_match('!^[A-Za-z0-9-_]+$!', $form_state['values']['fields'][$form_state['formatter_settings_edit']]['format_settings']['settings']['instance_settings']['id'])) { + if (!empty($form_state['values']['instance_settings']['id']) && !preg_match('!^[A-Za-z0-9-_]+$!', $form_state['values']['instance_settings']['id'])) { form_error($element, t('The id must include only letters, numbers, underscores and dashes.')); } } @@ -820,13 +766,7 @@ function field_group_field_info_max_weight($entity_type, $bundle, $context) { function field_group_delete_form($form, &$form_state, $group, $view_mode = 'form') { $form['#group'] = $group; - $admin_path = _field_ui_bundle_admin_path($group->entity_type, $group->bundle); - if ($view_mode == 'form') { - $admin_path .= '/fields'; - } - else { - $admin_path .= '/display/' . $view_mode; - } + $admin_path = _field_group_get_admin_path($group->entity_type, $group->bundle, $view_mode); $form['#redirect'] = array($admin_path); $output = confirm_form($form, t('Are you sure you want to delete the group %group?', array('%group' => t($group->label))), @@ -849,24 +789,83 @@ function field_group_delete_form($form, &$form_state, $group, $view_mode = 'form * * @todo we'll have to reset all view mode settings. */ -function field_group_delete_form_submit($form, &$form_state) { +function field_group_configure_form($form, &$form_state, $group, $view_mode = 'form') { + $form['#group'] = $group; + $form_state['#group'] = $group; + $form['#entity_type'] = $group->entity_type; + $form['#bundle'] = $group->bundle; + $form['#view_mode'] = $view_mode; - $group = $form['#group']; - $bundle = $group->bundle; - $entity_type = $group->entity_type; - $group->mode = $form_state['build_info']['args'][1]; + $form['label'] = array( + '#type' => 'textfield', + '#title' => t('Field group label'), + '#default_value' => $group->label, + '#weight' => -5, + '#element_validate' => array('field_group_format_settings_label_validate'), + ); - $bundles = field_info_bundles(); - $bundle_label = $bundles[$entity_type][$bundle]['label']; + $addition = module_invoke_all('field_group_format_settings', $group); + $form += $addition; + + // Give fieldgroup implementations the chance to alter the description. + if (!empty($addition['label']['#description'])) { + $form['label']['#description'] = $addition['label']['#description']; + } - field_group_group_delete($group); + $form['actions'] = array( + '#type' => 'actions' + ); + $form['actions']['submit'] = array( + '#type' => 'submit', + '#value' => 'Update', + ); - backdrop_set_message(t('The group %group has been deleted from the %type content type.', array('%group' => t($group->label), '%type' => $bundle_label))); + $form['actions']['cancel'] = array( + '#type' => 'link', + '#title' => 'Cancel', + '#href' => _field_group_get_admin_path($group->entity_type, $group->bundle, $view_mode), + ); - // Redirect. - $form_state['redirect'] = $form['#redirect']; + return $form; } +/** + * Submit handler for field_group_configure_form(). + */ +function field_group_configure_form_submit($form, &$form_state) { + $group = $form['#group']; + $group->mode = $form['#view_mode']; + $group->label = $form_state['values']['label']; + $group->format_settings['instance_settings'] = $form_state['values']['instance_settings']; + $group->format_settings['formatter'] = isset($form_state['values']['formatter']) ? $form_state['values']['formatter'] : ''; + + field_group_group_save($group, FALSE); + cache_clear_all('field_groups', 'cache_field'); + + $admin_path = _field_group_get_admin_path($form['#entity_type'], $form['#bundle'], $form['#view_mode']); + $form_state['redirect'] = $admin_path; +} + +/** + * Helper function to return the admin path for field UI. + * + * @param string $entity_type + * @param string $bundle + * @param string $view_mode + * + * @return string + * System path pointing to the field listing for the requsted view mode. + */ +function _field_group_get_admin_path($entity_type, $bundle, $view_mode) { + $admin_path = _field_ui_bundle_admin_path($entity_type, $bundle); + if ($view_mode == 'form') { + $admin_path .= '/fields'; + } else { + $admin_path .= '/display/' . $view_mode; + } + + return $admin_path; +} /** * Create vertical tabs. diff --git a/field_group.groups.inc b/field_group.groups.inc index ca959d3..345c486 100644 --- a/field_group.groups.inc +++ b/field_group.groups.inc @@ -956,9 +956,6 @@ function field_group_field_group_format_settings_alter(&$form, &$group) { */ function field_group_field_group_build_pre_render_alter(&$element) { - // Add the default field_group javascript. - $element['#attached']['js'][] = backdrop_get_path('module', 'field_group') . '/js/field_groups.js'; - // Move additional settings to the last multipage pane if configured that way. // Note that multipages MUST be in the root of the form. foreach (element_children($element) as $name) { @@ -976,34 +973,6 @@ function field_group_field_group_build_pre_render_alter(&$element) { } -/** - * Implements hook_field_group_field_ui_parent_requirements_alter(). - */ -function field_group_field_group_field_ui_parent_requirements_alter(&$parent_requirements, &$context) { - $parent_requirements = array( - 'multipage' => array( - 'parent' => 'multipage-group', - 'message' => 'Each Multipage element needs to have a parent Multipage group element.', - ), - 'htab' => array( - 'parent' => 'htabs', - 'message' => 'Each Horizontal tab element needs to have a parent Horizontal tabs group element.', - ), - 'accordion-item' => array( - 'parent' => 'accordion', - 'message' => 'Each Accordion item element needs to have a parent Accordion group element.', - ), - ); - - // On display overview tabs need to be checked. - if ($context['display_overview']) { - $parent_requirements['tab'] = array( - 'parent' => 'tabs', - 'message' => 'Each Vertical tab element needs to have a parent Vertical tabs group element.', - ); - } -} - /** * Implements hook_field_group_html_classes_alter(). */ diff --git a/field_group.module b/field_group.module index 2bfed29..14ff7ca 100644 --- a/field_group.module +++ b/field_group.module @@ -81,6 +81,24 @@ function field_group_menu() { 'access arguments' => array('administer site configuration'), ); + // Attempt to provide a title instead of just "configure" + $items["$path/groups/%field_group_menu"] = array( + 'load arguments' => array($entity_type, $bundle_arg, $bundle_pos, '%map'), + 'title callback' => 'field_group_menu_title', + 'title arguments' => array($group_position), + 'page callback' => 'backdrop_get_form', + 'page arguments' => array('field_group_configure_form', $group_position), + 'file' => 'field_group.field_ui.inc', + ) + $access; + $items["$path/groups/%field_group_menu/configure"] = array( + 'load arguments' => array($entity_type, $bundle_arg, $bundle_pos, '%map'), + 'title' => 'Configure', + 'page callback' => 'backdrop_get_form', + 'page arguments' => array('field_group_configure_form', $group_position), + 'type' => MENU_CALLBACK, + 'file' => 'field_group.field_ui.inc', + ) + $access; + $items["$path/groups/%field_group_menu/delete"] = array( 'load arguments' => array($entity_type, $bundle_arg, $bundle_pos, '%map'), 'title' => 'Delete', @@ -107,6 +125,17 @@ function field_group_menu() { return $items; } +/** + * Title callback: Returns the name of a given instance. + * + * @see field_group_menu() + */ +function field_group_menu_title($instance) { + debug($instance); + //return $instance['label']; + return 'configure'; +} + /** * Implements hook_permission(). */ @@ -313,7 +342,7 @@ function field_group_field_group_format_settings($group) { if (isset($formatter['instance_settings']['id'])) { $form['instance_settings']['id'] = array( - '#title' => t('ID'), + '#title' => t('ID attribute'), '#type' => 'textfield', '#default_value' => isset($group->format_settings['instance_settings']['id']) ? $group->format_settings['instance_settings']['id'] : (isset($formatter['instance_settings']['id']) ? $formatter['instance_settings']['id'] : ''), '#weight' => 10, @@ -549,15 +578,6 @@ function field_group_field_group_format_summary($group) { $output .= '' . $key . ' '; - if (isset($group_form['instance_settings'], $group_form['instance_settings'][$key]['#options'])) { - if (is_array($value)) { - $value = implode(', ', array_filter($value)); - } - else { - $value = $group_form['instance_settings'][$key]['#options'][$value]; - } - } - // Shorten the string. if (backdrop_strlen($value) > 38) { $value = truncate_utf8($value, 50, TRUE, TRUE); @@ -899,7 +919,7 @@ function field_group_build_entity_groups(&$vars, $type) { field_group_remove_empty_form_groups('form', $element, $groups, $element['#groups'], $element['#entity_type']); } - // Add the default field_group javascript. + // Add the default field_group javascript and stylesheet. $element['#attached']['js'][] = backdrop_get_path('module', 'field_group') . '/js/field_group.js'; // Allow others to alter the pre_rendered build. diff --git a/js/field_group.field_ui.js b/js/field_group.field_ui.js index ca908bd..26e11c5 100644 --- a/js/field_group.field_ui.js +++ b/js/field_group.field_ui.js @@ -1,3 +1,7 @@ +/** + * @file + * Attaches the behaviors for the Field UI of the Field Group module. + */ (function($) { @@ -134,4 +138,4 @@ Backdrop.fieldUIDisplayOverview.group.prototype = { }; -})(jQuery); \ No newline at end of file +})(jQuery);