function ds_field_ui_regions in Display Suite 7.2
Same name and namespace in other branches
- 8.4 includes/field_ui.inc \ds_field_ui_regions()
- 8.2 includes/field_ui.inc \ds_field_ui_regions()
- 8.3 includes/field_ui.inc \ds_field_ui_regions()
- 7 ds.field_ui.inc \ds_field_ui_regions()
Add Regions to 'Manage fields' or 'Manage display' screen.
Parameters
$form: The form to add layout fieldset and extra Display Suite fields.
$form_state: The current form state.
1 string reference to 'ds_field_ui_regions'
- ds_field_ui_fields_layouts in includes/
ds.field_ui.inc - Adds the Display Suite fields and layouts to the form.
File
- includes/
ds.field_ui.inc, line 270 - Field UI functions for Display Suite.
Code
function ds_field_ui_regions($form, $form_state) {
// Get the entity_type, bundle and view mode.
$entity_type = $form['#entity_type'];
$bundle = $form['#bundle'];
$view_mode = $form['#view_mode'];
// Ignore fieldgroup options.
if (isset($form_state['no_field_group'])) {
unset($form['fields']['_add_new_group']);
$form['additional_settings']['field_group']['#access'] = FALSE;
}
// Check layout.
$layout = isset($form['#ds_layout']) ? $form['#ds_layout'] : FALSE;
// Change UI to add Region column if we have a layout.
if ($layout) {
$table =& $form['fields'];
if ($view_mode != 'form') {
$table['#header'] = array(
t('Field'),
t('Weight'),
t('Parent'),
t('Region'),
t('Label'),
array(
'data' => t('Format'),
'colspan' => 3,
),
);
}
else {
$table['#header'] = array(
t('Label'),
t('Weight'),
t('Parent'),
t('Region'),
t('Name'),
t('Field'),
t('Widget'),
array(
'data' => t('Operations'),
'colspan' => 2,
),
);
}
// Remove label and format for views.
if ($entity_type == 'ds_views') {
$table['#header'][4] = '';
}
$table['#regions'] = array();
foreach ($layout->regions as $region_key => $region_title) {
$region_options[$region_key] = $region_title;
$table['#regions'][$region_key] = array(
'title' => $region_title,
'message' => t('No fields are displayed in this region'),
);
}
// Let other modules alter the regions.
$context = array(
'entity_type' => $entity_type,
'bundle' => $bundle,
'view_mode' => $view_mode,
);
$region_info = array(
'region_options' => &$region_options,
'table_regions' => &$table['#regions'],
);
drupal_alter('ds_layout_region', $context, $region_info);
$region_options['hidden'] = $view_mode != 'form' ? t('Disabled') : t('Hidden');
$table['#regions']['hidden'] = array(
'title' => $view_mode != 'form' ? t('Disabled') : t('Hidden'),
'message' => t('No fields are hidden.'),
);
$region = array(
'#type' => 'select',
'#options' => $region_options,
'#default_value' => 'hidden',
'#attributes' => array(
'class' => array(
'ds-field-region',
),
),
);
$limit_items = array(
'#type' => 'textfield',
'#size' => 2,
'#default_value' => '',
'#weight' => 10,
'#default_value' => '#',
'#prefix' => '<div class="limit-float">',
'#suffix' => '</div><div class="clearfix"></div>',
'#attributes' => array(
'alt' => t('Enter a number to limit the number of items or \'delta\' to print a specific delta (usually configured in views or found in entity->ds_delta). Leave empty to display them all. Note that depending on the formatter settings, this option might not always work.'),
'title' => t('Enter a number to limit the number of items or \'delta\' to print a specific delta (usually configured in views or found in entity->ds_delta). Leave empty to display them all. Note that depending on the formatter settings, this option might not always work.'),
),
);
// Hide this if we formatter_settings_edit is not empty so it doesn't confuse users.
if (!empty($form_state['formatter_settings_edit'])) {
$limit_items['#access'] = FALSE;
}
// Update existing rows by changing rowHandler and adding regions.
foreach (element_children($table) as $name) {
$row =& $table[$name];
$row['#js_settings'] = array(
'rowHandler' => 'ds',
);
$row['#region_callback'] = 'ds_field_ui_row_region';
// Remove hidden format.
if (isset($row['format']['type']['#options']['hidden'])) {
unset($row['format']['type']['#options']['hidden']);
}
// Add label class.
if (isset($row['label'])) {
if (isset($form_state['formatter_settings']) && isset($form_state['formatter_settings'][$name]['ft'])) {
if (!empty($form_state['formatter_settings'][$name]['ft']['lb'])) {
$row['human_name']['#markup'] = check_plain($form_state['formatter_settings'][$name]['ft']['lb']) . ' ' . t('(Original: !orig)', array(
'!orig' => $row['human_name']['#markup'],
));
}
}
}
// Limit items.
$field_info = field_info_field($name);
if (isset($field_info['cardinality']) && $field_info['cardinality'] != 1 && $view_mode != 'form') {
$row['format']['type']['#prefix'] = '<div class="limit-float">';
$row['format']['type']['#suffix'] = '</div>';
$row['format']['limit'] = $limit_items;
$row['format']['limit']['#default_value'] = isset($layout->settings['limit']) && isset($layout->settings['limit'][$name]) ? $layout->settings['limit'][$name] : '#';
}
// Disable label and format for views.
if ($entity_type == 'ds_views') {
$row['label']['#access'] = FALSE;
}
// Add region.
$split = $view_mode != 'form' ? 7 : 6;
if ($row['#row_type'] == 'group' && $view_mode == 'form') {
$split = $view_mode != 'form' ? 8 : 7;
}
$second = array_splice($row, $split);
$row['region'] = $region;
$row['region']['#default_value'] = isset($layout->settings['fields'][$name]) && isset($region_options[$layout->settings['fields'][$name]]) ? $layout->settings['fields'][$name] : 'hidden';
$row = array_merge($row, $second);
}
}
return $form;
}