function ds_fields_display_form in Display Suite 6
Same name and namespace in other branches
- 6.3 includes/ds.display.inc \ds_fields_display_form()
- 6.2 includes/ds.display.inc \ds_fields_display_form()
Add fields to display overview form.
2 calls to ds_fields_display_form()
- ds_display_overview_form in includes/
ds.display.inc - Menu callback; presents a listing of fields display settings for an object type.
- views_plugin_ds_fields_view::options_form in views/
views_plugin_ds_fields_view.inc - Provide a form for setting options.
File
- includes/
ds.display.inc, line 270 - Display overview form.
Code
function ds_fields_display_form(&$form, $display_settings, $fields = array()) {
global $base_url;
$module = $form['#module'];
$build_mode = $form['#build_mode'];
$type = $form['#type_name'];
$extra = $form['#extra'];
if (empty($fields)) {
$fields = ds_get_fields($module, $type, $build_mode, $extra, TRUE);
}
// Break form build in case no fields.
if (empty($fields)) {
return;
}
$field_style_options = ds_styles('fields');
$default_properties = ds_field_default_form_properties($build_mode);
$default = !empty($form[key($fields)]) ? $form[key($fields)] : $default_properties;
foreach ($fields as $field => $value) {
$summary = '';
// Add form variable to let the template system know about the fields.
$form['#fields'][] = $field;
// Every field starts with the default value
$form[$field] = $default;
// Store the type.
$form[$field][$build_mode]['type'] = array(
'#type' => 'value',
'#value' => $value['type'],
);
// Field key, parent key and depth.
$parent = ds_default_value($display_settings, $build_mode, 'fields', $field, 'parent', '');
if (!isset($fields[$parent])) {
$parent = '';
}
$form[$field][$build_mode]['#depth'] = !empty($parent) ? 1 : 0;
$form[$field][$build_mode]['parent_id'] = array(
'#type' => 'hidden',
'#default_value' => $parent,
'#attributes' => array(
'class' => 'ds-parent-id',
),
'#size' => 20,
);
$form[$field][$build_mode]['field_id'] = array(
'#type' => 'hidden',
'#value' => $field,
'#size' => 20,
'#attributes' => array(
'class' => 'ds-field-id',
),
);
// Populate/override the fields with the saved values
$label_format = isset($value['display_settings'][$build_mode]['label']['format']) ? $value['display_settings'][$build_mode]['label']['format'] : ds_default_value($display_settings, $build_mode, 'fields', $field, 'labelformat', DS_DEFAULT_LABEL_FORMAT);
$form[$field][$build_mode]['label']['format']['#default_value'] = $label_format;
$summary .= '<span class="label-info">Label: ' . $label_format . '</span>';
// Labels.
$label_value = ds_default_value($display_settings, $build_mode, 'fields', $field, 'label_value', '');
$form[$field][$build_mode]['label_value'] = array(
'#type' => 'textfield',
'#title' => t('Label text'),
'#default_value' => $label_value,
'#description' => !empty($label_value) ? t('The original value was: @label', array(
'@label' => $value['title'],
)) : t('Change the default label text, which will be translatable.'),
);
// Label.
$form[$field]['human_name']['#value'] = !empty($label_value) ? check_plain($label_value) : (isset($value['label']) ? $value['label'] : $value['title']);
// Weight.
$form[$field]['weight']['#default_value'] = ds_default_value($display_settings, $build_mode, 'fields', $field, 'weight', DS_DEFAULT_WEIGHT);
$form[$field]['ds_weight']['#default_value'] = ds_default_value($display_settings, $build_mode, 'fields', $field, 'weight', DS_DEFAULT_WEIGHT);
// Formatting.
$form[$field][$build_mode]['format']['#options'] = isset($value['properties']['formatters']) ? $value['properties']['formatters'] : array();
$format = ds_default_value($display_settings, $build_mode, 'fields', $field, 'format', '');
if (empty($format) && isset($value['properties']['formatters'])) {
$format = key($value['properties']['formatters']);
}
$form[$field][$build_mode]['format']['#default_value'] = $format;
$form[$field][$build_mode]['format']['#access'] = count($form[$field][$build_mode]['format']['#options']) == 0 ? FALSE : TRUE;
if (!empty($format)) {
$summary .= ' - <span class="format-info">Format: ' . $form[$field][$build_mode]['format']['#options'][$format] . '</span>';
}
// Class.
$class = ds_default_value($display_settings, $build_mode, 'fields', $field, 'css-class', '');
$class_values = explode(' ', $class);
$human_names = array();
if (!empty($class_values)) {
$human_names = _ds_styles_match_options($field_style_options, array_filter($class_values));
}
$form[$field][$build_mode]['css-class']['#default_value'] = explode(' ', $class);
if (!empty($human_names)) {
$summary .= '<span class="style-info"> - Styles: ' . implode(', ', $human_names) . '</span>';
}
else {
$summary .= '<span class="style-info"></span>';
}
// Region.
$form[$field][$build_mode]['region']['#default_value'] = ds_default_value($display_settings, $build_mode, 'fields', $field, 'region', DS_DEFAULT_REGION);
// Settings summary.
$form[$field][$build_mode]['summary'] = array(
'#type' => 'markup',
'#value' => $summary,
);
}
}