function ds_field_ui_layout_change in Display Suite 7.2
Same name and namespace in other branches
- 7 ds.field_ui.inc \ds_field_ui_layout_change()
Change a layout for a given entity.
Parameters
$entity_type: The name of the entity.
$bundle: The name of the bundle.
$view_mode: The name of the view mode.
1 string reference to 'ds_field_ui_layout_change'
- _ds_menu in includes/
ds.registry.inc - Implements hook_menu().
File
- includes/
ds.field_ui.inc, line 451 - Field UI functions for Display Suite.
Code
function ds_field_ui_layout_change($form, $form_state, $entity_type = '', $bundle = '', $view_mode = '', $new_layout = '') {
$old_layout = NULL;
$all_layouts = ds_get_layout_info();
if (!empty($entity_type) && !empty($bundle) && !empty($view_mode)) {
$old_layout = ds_get_layout($entity_type, $bundle, $view_mode, FALSE);
}
if ($old_layout && isset($all_layouts[$new_layout])) {
$new_layout_key = $new_layout;
$new_layout = $all_layouts[$new_layout];
$form['#entity_type'] = $entity_type;
$form['#bundle'] = $bundle;
$form['#view_mode'] = $view_mode;
$form['#old_layout'] = $old_layout;
$form['#new_layout'] = $new_layout;
$form['#new_layout_key'] = $new_layout_key;
$form['#export_id'] = $entity_type . '|' . $bundle . '|' . $view_mode;
$form['info'] = array(
'#markup' => t('You are changing from %old to %new layout for !bundle in !view_mode view mode.', array(
'%old' => $old_layout['label'],
'%new' => $new_layout['label'],
'!bundle' => $bundle,
'!view_mode' => $view_mode,
)),
'#prefix' => "<div class='change_ds_layout_info'>",
'#suffix' => "</div>",
);
// Old region options.
$regions = array();
foreach ($old_layout['regions'] as $key => $title) {
$regions[$key] = $title;
}
// Let other modules alter the regions.
// For old regions.
$context = array(
'entity_type' => $entity_type,
'bundle' => $bundle,
'view_mode' => $view_mode,
);
$region_info = array(
'region_options' => $regions,
);
drupal_alter('ds_layout_region', $context, $region_info);
$regions = $region_info['region_options'];
$form['#old_layout']['regions'] = $regions;
// For new regions.
$region_info = array(
'region_options' => $new_layout['regions'],
);
drupal_alter('ds_layout_region', $context, $region_info);
$new_layout['regions'] = $region_info['region_options'];
$form['#new_layout']['regions'] = $new_layout['regions'];
// Display the region options
$selectable_regions = array(
'' => t('- None -'),
) + $new_layout['regions'];
$form['regions_pre']['#markup'] = '<div class="ds-layout-regions">';
foreach ($regions as $region => $region_title) {
$form['region_' . $region] = array(
'#type' => 'container',
);
$form['region_' . $region]['ds_label_' . $region] = array(
'#markup' => 'Fields in <span class="change_ds_layout_old_region"> ' . $region_title . '</span> go into',
);
$form['region_' . $region]['ds_' . $region] = array(
'#type' => 'select',
'#options' => $layout_options = $selectable_regions,
'#default_value' => $region,
);
}
$form['regions_post']['#markup'] = '</div>';
// Show previews from old and new layouts
$form['preview'] = array(
'#type' => 'container',
'#prefix' => '<div class="ds-layout-preview"/>',
'#suffix' => '</div>',
);
$fallback_image = drupal_get_path('module', 'ds') . '/images/preview.png';
$old_image = isset($old_layout['image']) && !empty($old_layout['image']) ? $old_layout['path'] . '/' . $old_layout['layout'] . '.png' : $fallback_image;
if (isset($old_layout['panels']) && !empty($old_layout['panels']['icon'])) {
$old_image = $old_layout['panels']['path'] . '/' . $old_layout['panels']['icon'];
}
$new_image = isset($new_layout['image']) && !empty($new_layout['image']) ? $new_layout['path'] . '/' . $new_layout_key . '.png' : $fallback_image;
if (isset($new_layout['panels']) && !empty($new_layout['panels']['icon'])) {
$new_image = $new_layout['panels']['path'] . '/' . $new_layout['panels']['icon'];
}
$arrow = drupal_get_path('module', 'ds') . '/images/arrow.png';
$form['preview']['old_layout'] = array(
'#markup' => '<div class="ds-layout-preview-image"><img src="' . base_path() . $old_image . '"/></div>',
);
$form['preview']['arrow'] = array(
'#markup' => '<div class="ds-layout-preview-arrow"><img src="' . base_path() . $arrow . '"/></div>',
);
$form['preview']['new_layout'] = array(
'#markup' => '<div class="ds-layout-preview-image"><img src="' . base_path() . $new_image . '"/></div>',
);
$form['#attached']['css'][] = drupal_get_path('module', 'ds') . '/css/ds.admin.css';
// Submit button
$form['actions'] = array(
'#type' => 'actions',
);
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
'#prefix' => '<div class="ds-layout-change-save">',
'#suffix' => '</div>',
);
}
else {
$form['nothing'] = array(
'#markup' => t('No valid configuration found.'),
);
}
return $form;
}