You are here

function ds_field_ui_layout_change in Display Suite 7

Same name and namespace in other branches
  1. 7.2 includes/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 ./ds.module
Implements hook_menu().

File

./ds.field_ui.inc, line 344
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;
  if (!empty($entity_type) && !empty($bundle) && !empty($view_mode)) {
    $old_layout = ds_get_layout($entity_type, $bundle, $view_mode, FALSE);
  }
  $all_layouts = ds_get_layout_info();
  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. On this screen, you can map the old regions to the new regions.', array(
        '%old' => $old_layout['label'],
        '%new' => $new_layout['label'],
        '!bundle' => $bundle,
        '!view_mode' => $view_mode,
      )),
    );

    // 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'];

    // 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'];

    // Create field selects. Use previous region as default value.
    foreach ($new_layout['regions'] as $region => $region_title) {
      $form['ds_' . $region] = array(
        '#type' => 'select',
        '#multiple' => TRUE,
        '#title' => $region_title,
        '#options' => $regions,
        '#default_value' => $region,
      );
    }
    $form['actions'] = array(
      '#type' => 'actions',
    );
    $form['actions']['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Save'),
    );
    $form['actions']['cancel'] = array(
      '#type' => 'link',
      '#title' => t('Cancel'),
      '#href' => isset($_REQUEST['destination']) ? $_REQUEST['destination'] : '',
    );
  }
  else {
    $form['nothing'] = array(
      '#markup' => t('No valid configuration found.'),
    );
  }
  return $form;
}