Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 1 addition & 14 deletions field_group.api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/

Expand Down Expand Up @@ -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().
*
Expand Down
217 changes: 108 additions & 109 deletions field_group.field_ui.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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'] = '<div id="field-display-overview-wrapper">';
$form['fields']['#suffix'] = '</div>';
Expand Down Expand Up @@ -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);
}

Expand All @@ -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.
Expand Down Expand Up @@ -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:') . ' <span class="formatter-name">' . $group->format_type . '</span>',
),
// 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.
Expand Down Expand Up @@ -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'));
}

}

/**
Expand Down Expand Up @@ -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.'));
}
}
Expand All @@ -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.'));
}
}
Expand Down Expand Up @@ -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))),
Expand All @@ -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.
Expand Down
31 changes: 0 additions & 31 deletions field_group.groups.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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().
*/
Expand Down
Loading