You are here

function _ds_field_ui_table_layouts_preview in Display Suite 7.2

Same name and namespace in other branches
  1. 8.4 includes/field_ui.inc \_ds_field_ui_table_layouts_preview()
  2. 8.2 includes/field_ui.inc \_ds_field_ui_table_layouts_preview()
  3. 8.3 includes/field_ui.inc \_ds_field_ui_table_layouts_preview()

Add the layout previews to the Field UI screen.

Parameters

$form: A collection of form properties.

$form_state: The state of the form

$ds_layouts: Collection of all the layouts

$layout: Current selected layout

$entity_type: The name of the entity type.

$bundle: The name of the bundle

$view_mode: The name of the view_mode

1 call to _ds_field_ui_table_layouts_preview()
_ds_field_ui_table_layouts in includes/ds.field_ui.inc
Add the layouts fieldset on the Field UI screen.

File

includes/ds.field_ui.inc, line 1860
Field UI functions for Display Suite.

Code

function _ds_field_ui_table_layouts_preview(&$form, &$form_state, $ds_layouts, $layout, $entity_type, $bundle, $view_mode) {
  $layout_string = '';
  $form['additional_settings']['ds_layouts']['layout'] = array(
    '#type' => 'select',
    '#title' => t('Select a layout'),
    '#options' => $layout->layout_options,
    '#default_value' => isset($layout->layout) && empty($layout->disabled) ? $layout->layout : '',
    '#prefix' => '<div class="ds-select-layout">',
    '#suffix' => '</div>',
    '#weight' => -1,
    '#ajax' => array(
      'callback' => 'ds_field_ui_table_layouts_preview_callback',
      'wrapper' => 'ds_layout_wrapper',
    ),
  );
  if (!isset($layout->layout)) {
    $form['additional_settings']['ds_layouts']['layout']['#description'] = t("A layout must be selected to enable Display Suite functionality.");
  }
  $form['additional_settings']['ds_layouts']['preview'] = array(
    '#type' => 'container',
    '#prefix' => '<div id="ds_layout_wrapper">',
    '#suffix' => '</div>',
    '#weight' => -3,
  );
  if (isset($layout->layout) || isset($form_state['values']['additional_settings']['layout'])) {
    $layout_string = isset($form_state['values']['additional_settings']['layout']) ? $form_state['values']['additional_settings']['layout'] : $layout->layout;
  }
  if (!empty($layout_string)) {
    $chosen_layout = $ds_layouts[$layout_string];
    if (empty($chosen_layout['flexible'])) {
      $selected = '<strong>' . $chosen_layout['label'] . '</strong>';
      $selected .= '<br/>' . t('The default template can be found in %path', array(
        '%path' => $chosen_layout['path'],
      ));
      $suggestions = t('Template suggestions') . ':<ul>';
      $suggestions_array = array();
      $suggestions_array[0] = $layout_string . '--' . $entity_type;
      $suggestions_array[2] = $layout_string . '--' . $entity_type . '-' . $bundle;
      $suggestions_array[4] = $layout_string . '--' . $entity_type . '--{id}';
      if (!isset($form_state['no_view_mode_suggestions']) && $view_mode != 'default') {
        $suggestions_array[1] = $layout_string . '--' . $entity_type . '-' . $view_mode;
        $suggestions_array[3] = $layout_string . '--' . $entity_type . '-' . $bundle . '-' . $view_mode;
      }
      ksort($suggestions_array);
      $suggestions .= '<ul><li>' . implode('.tpl.php</li><li>', $suggestions_array) . '.tpl.php</li></ul>';
    }
    else {
      $suggestions = '';
      $selected = t('You have selected the flexible %layout_label layout.', array(
        '%layout_label' => $chosen_layout['label'],
        '%path' => $chosen_layout['path'],
      ));
    }
    if (isset($form_state['values']['additional_settings']['layout']) || !empty($layout) && isset($layout->regions)) {
      $fallback_image = drupal_get_path('module', 'ds') . '/images/preview.png';
      $current_layout = isset($form_state['values']['additional_settings']['layout']) && (!isset($layout->layout) || $form_state['values']['additional_settings']['layout'] != $layout->layout) ? t('Current layout (after save)') : t('Current layout');
      $image = isset($chosen_layout['image']) && !empty($chosen_layout['image']) ? $chosen_layout['path'] . '/' . $layout_string . '.png' : $fallback_image;
      if (isset($chosen_layout['panels']) && !empty($chosen_layout['panels']['icon'])) {
        $image = $chosen_layout['panels']['path'] . '/' . $chosen_layout['panels']['icon'];
      }
      $form['additional_settings']['ds_layouts']['preview']['title'] = array(
        '#markup' => '<div class="ds-layout-preview-title">' . $current_layout . '</div>',
      );
      $form['additional_settings']['ds_layouts']['preview']['image'] = array(
        '#markup' => '<div class="ds-layout-preview-image"><img src="' . base_path() . $image . '"/></div>',
      );
      $form['additional_settings']['ds_layouts']['preview']['info'] = array(
        '#type' => 'container',
        '#attributes' => array(
          'class' => array(
            'ds-layout-preview-suggestion',
          ),
        ),
      );
      $form['additional_settings']['ds_layouts']['preview']['info']['suggestions'] = array(
        '#markup' => '<p>' . $selected . '</p><p>' . t('!suggestions', array(
          '!suggestions' => strtr($suggestions, '_', '-'),
        )) . '</p>',
      );
      if (!empty($chosen_layout['css'])) {
        $disable_css = FALSE;
        if (isset($layout->settings['layout_disable_css'])) {
          $disable_css = $layout->settings['layout_disable_css'];
        }
        $form['additional_settings']['ds_layouts']['preview']['info']['settings']['disable_css'] = array(
          '#type' => 'checkbox',
          '#title' => t('Disable layout CSS styles'),
          '#default_value' => $disable_css,
        );
      }
    }
    if (isset($form_state['values']['additional_settings']['layout']) && (!isset($layout->layout) || $form_state['values']['additional_settings']['layout'] != $layout->layout)) {

      // Get admin path.
      $admin_path = _field_ui_bundle_admin_path($entity_type, $bundle);
      if ($view_mode != 'form') {
        $admin_path .= '/display';
      }
      else {
        $admin_path .= '/fields';
      }

      // If regions aren't set we don't have to move fields.
      if (isset($layout->regions)) {
        $url = 'admin/structure/ds/change-layout/' . $entity_type . '/' . $bundle . '/' . $view_mode . '/' . $layout_string . '?destination=' . $admin_path;
        $form['#validate'][] = 'ds_field_ui_change_layout_validate';
      }
      else {
        $url = $admin_path;
      }
      if ($view_mode != 'default' && $view_mode != 'form') {
        $url .= '/' . $view_mode;
      }
      $form['layout_changed_url'] = array(
        '#type' => 'value',
        '#value' => $url,
      );
      $form['#submit'][] = 'ds_field_ui_change_layout_submit';
    }
  }
}