You are here

function _ds_field_ui_table_layouts in Display Suite 7

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

Add the layouts fieldset on the Field UI screen.

Parameters

$entity_type: The name of the entity type.

$bundle: The name of the bundle

$view_mode: The name of the view_mode

$form: A collection of form properties.

1 call to _ds_field_ui_table_layouts()
ds_field_ui_fields_layouts in ./ds.field_ui.inc
Adds the Display Suite fields and layouts to the form.

File

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

Code

function _ds_field_ui_table_layouts($entity_type, $bundle, $view_mode, &$form, $form_state) {
  $layout_options = array();
  $ds_layouts = ds_get_layout_info();
  $layout_options = array(
    '' => t('- None -'),
  );
  foreach ($ds_layouts as $key => $layout) {
    $optgroup = 'Display suite';

    // Continue if view mode is form and the form property is not ok.
    if ($view_mode == 'form' && (!isset($layout['form']) || isset($layout['form']) && !$layout['form'])) {
      continue;
    }
    elseif ($view_mode != 'form' && isset($layout['form']) && $layout['form']) {
      continue;
    }

    // Panels can not be used on Views fields.
    if (!empty($layout['module']) && $layout['module'] == 'panels' && isset($form_state['no_panels'])) {
      continue;
    }

    // Create new layout optoin group.
    if (!empty($layout['module'])) {
      $optgroup = drupal_ucfirst($layout['module']);
    }
    if (!isset($layout_options[$optgroup])) {
      $layout_options[$optgroup] = array();
    }

    // Stack the layout.
    $layout_options[$optgroup][$key] = $layout['label'];
  }

  // If there is only one $optgroup, move it to the root.
  if (count($layout_options) == 2) {
    $options = $layout_options[$optgroup];
    $layout_options = array_merge(array(
      '' => t('- None -'),
    ), $options);
  }

  // Add layouts form.
  $form['additional_settings']['ds_layouts'] = array(
    '#type' => 'fieldset',
    '#title' => t('Layout for !bundle in !view_mode', array(
      '!bundle' => str_replace('_', ' ', $bundle),
      '!view_mode' => str_replace('_', ' ', $view_mode),
    )),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#parents' => array(
      'additional_settings',
    ),
  );
  ctools_include('export');
  $layout = new stdClass();
  $ds_layout_settings = ctools_export_crud_load_all('ds_layout_settings');
  $form['#panel'] = FALSE;
  if (isset($ds_layout_settings[$form['#export_id']])) {
    $layout = $ds_layout_settings[$form['#export_id']];

    // Make sure this does not break in case there was
    // a layout created with Panel view modes.
    if (isset($layout->settings['ds_panels'])) {
      $layout = NULL;
      $form['#panel'] = TRUE;
    }
  }
  if (!empty($layout) && isset($layout->layout) && isset($ds_layouts[$layout->layout])) {
    $chosen_layout = $ds_layouts[$layout->layout];
    $layout_string = $layout->layout;
    if (empty($chosen_layout['flexible'])) {
      if (isset($chosen_layout['module']) && $chosen_layout['module'] == 'panels') {
        $layout_string = $chosen_layout['panels']['theme'];
      }
      $selected = t('You have selected the %layout_label layout. The default template can be found in %path', array(
        '%layout_label' => $chosen_layout['label'],
        '%path' => $chosen_layout['path'],
      ));
      $suggestions = t('Template suggestions') . ':<ul>';
      $suggestions .= '<li>' . $layout_string . '--' . $entity_type . '.tpl.php</li>';
      $suggestions .= '<li>' . $layout_string . '--' . $entity_type . '-' . $bundle . '.tpl.php</li>';
      if (!isset($form_state['no_view_mode_suggestions'])) {
        $suggestions .= '<li>' . $layout_string . '--' . $entity_type . '-' . $bundle . '-' . $view_mode . '.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'],
      ));
    }
    $layout->settings = $layout->settings;
    $layout->regions = $chosen_layout['regions'];
    $form['#ds_layout'] = $layout;
  }
  $form['additional_settings']['ds_layouts']['layout'] = array(
    '#type' => 'select',
    '#title' => t('Select a layout'),
    '#options' => $layout_options,
    '#default_value' => isset($layout->layout) ? $layout->layout : '',
    '#weight' => -1,
  );

  // Apply button.
  if (isset($layout->layout)) {
    $form['additional_settings']['ds_layouts']['ds_layout_apply'] = array(
      '#type' => 'submit',
      '#value' => t('Apply'),
      '#disabled' => TRUE,
      '#weight' => 0,
    );
  }
  if (isset($layout->export_type) && $layout->export_type == 3) {
    $form['additional_settings']['ds_layouts']['revert'] = array(
      '#markup' => l(t('This layout is overridden. Click to revert to default settings.'), 'admin/structure/ds/revert-layout/' . $form['#export_id'], array(
        'query' => drupal_get_destination(),
      )),
      '#weight' => 1,
    );
  }
  $form['additional_settings']['ds_layouts']['hide_empty_regions'] = array(
    '#type' => 'checkbox',
    '#title' => t('Hide empty regions'),
    '#default_value' => isset($layout->settings['hide_empty_regions']) ? $layout->settings['hide_empty_regions'] : FALSE,
    '#weight' => 2,
    '#access' => empty($chosen_layout['flexible']),
  );
  $form['additional_settings']['ds_layouts']['hide_sidebars'] = array(
    '#type' => 'checkbox',
    '#title' => t('Disable Drupal blocks/regions'),
    '#description' => t('Check this to have the page disable all sidebar regions displayed in the theme. Note that some themes support this setting better than others. If in doubt, try with stock themes to see.'),
    '#default_value' => isset($layout->settings['hide_sidebars']) ? $layout->settings['hide_sidebars'] : FALSE,
    '#access' => $view_mode != 'form',
    '#weight' => 3,
  );
  if (!empty($layout) && isset($layout->regions)) {
    $form['additional_settings']['ds_layouts']['suggestions'] = array(
      '#markup' => '<p>' . $selected . '</p><p>' . t('!suggestions', array(
        '!suggestions' => strtr($suggestions, '_', '-'),
      )) . '</p>',
    );

    // Add extra classes for the regions to have more control while theming.
    $form['additional_settings']['ds_classes'] = array(
      '#type' => 'fieldset',
      '#title' => t('Extra classes for regions'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
      '#parents' => array(
        'additional_settings',
      ),
      '#access' => empty($chosen_layout['flexible']),
    );
    $styles = _ds_styles();
    if (!empty($styles)) {
      foreach (array_keys($layout->regions) as $region) {
        $form['additional_settings']['ds_classes'][$region] = array(
          '#type' => 'select',
          '#multiple' => TRUE,
          '#options' => $styles,
          '#title' => t('Class for @region', array(
            '@region' => $region,
          )),
          '#default_value' => isset($layout->settings['classes'], $layout->settings['classes'][$region]) ? $layout->settings['classes'][$region] : '',
        );
      }
      $form['additional_settings']['ds_classes']['info'] = array(
        '#markup' => l(t('Manage region styles'), 'admin/structure/ds/styles', array(
          'query' => drupal_get_destination(),
        )),
      );
    }
    else {
      $form['additional_settings']['ds_classes']['info'] = array(
        '#markup' => '<p>' . t('You have not defined any styles which can be used on regions.') . '</p><p>' . l(t('Manage region styles'), 'admin/structure/ds/styles', array(
          'query' => drupal_get_destination(),
        )) . '</p>',
      );
    }
  }
  else {
    if ($view_mode != 'form') {

      // See if we can clone from another view mode.
      $options = array();
      $ds_layout_settings = ctools_export_crud_load_all('ds_layout_settings');
      foreach ($ds_layout_settings as $row) {

        // Do not clone from form layouts.
        if ($row->view_mode == 'form') {
          continue;
        }
        if ($row->entity_type == $entity_type && $row->bundle == $bundle && !isset($row->settings['ds_panels'])) {
          $options[$row->id] = drupal_ucfirst($row->entity_type) . ' > ' . drupal_ucfirst($row->bundle) . ' > ' . drupal_ucfirst($row->view_mode);
        }
      }
      if (!empty($options)) {

        // Clone from another layout.
        $form['additional_settings']['ds_clone'] = array(
          '#type' => 'fieldset',
          '#title' => t('Clone layout'),
          '#collapsible' => TRUE,
          '#collapsed' => TRUE,
          '#parents' => array(
            'additional_settings',
          ),
        );
        $form['additional_settings']['ds_clone']['clone'] = array(
          '#title' => t('Select an existing layout to clone.'),
          '#type' => 'select',
          '#options' => $options,
          '#weight' => 20,
        );
        $form['additional_settings']['ds_clone']['clone_submit'] = array(
          '#type' => 'submit',
          '#value' => t('Clone layout'),
          '#submit' => array(
            'ds_field_ui_layout_clone',
          ),
          '#weight' => 21,
        );
      }
    }
  }
  $form['additional_settings']['ds_layouts']['id'] = array(
    '#type' => 'value',
    '#value' => isset($layout->id) ? $layout->id : $form['#export_id'],
  );
  $form['additional_settings']['ds_layouts']['old_layout'] = array(
    '#type' => 'value',
    '#value' => isset($layout->layout) ? $layout->layout : 0,
  );

  // Add validate and submit handlers. Layout needs be first so
  // we can reset the type key for Field API fields.
  $form['#validate'][] = 'ds_field_ui_layouts_validate';
  $submit = $form['#submit'];
  $form['#submit'] = array(
    'ds_field_ui_layouts_save',
  );
  $form['#submit'] = array_merge($form['#submit'], $submit);
}