You are here

function ds_panels_layout in Display Suite 7

Return the Panels layout settings form.

1 string reference to 'ds_panels_layout'
ds_panels_field_ui in modules/ds_extras/ds_extras.panels.inc
Manage display screen with panels editor.

File

modules/ds_extras/ds_extras.panels.inc, line 228
Administrative functions for DS panels.

Code

function ds_panels_layout($form, $form_state, $entity_type, $bundle, $view_mode, $ds_layout, $panel_layout, $layout_tab_first) {
  $form['#entity_type'] = $entity_type;
  $form['#bundle'] = $bundle;
  $form['#view_mode'] = $view_mode;
  $form['#export_id'] = $entity_type . '|' . $bundle . '|' . $view_mode;
  $form['#ds_panels_update'] = !empty($ds_layout) ? TRUE : FALSE;

  // Include panel functions.
  ctools_include('plugins', 'panels');
  ctools_include('common', 'panels');

  // Add css
  $form['#attached']['css'][] = drupal_get_path('module', 'ds_extras') . '/ds_extras.panels.admin.css';

  // When panel_layout is empty, render the layout selector with links.
  if (empty($ds_layout) && empty($panel_layout)) {
    $layout_tab_first = TRUE;
    $layouts = panels_common_get_allowed_layouts('ds_panels');

    // We don't allow the flexible builder from here directly.
    unset($layouts['flexible']);
    $form['layout'] = array(
      '#markup' => '<p>' . t('Select a layout to use for !entity_type > !bundle > !view_mode.<br />You can use flexible layouts, but you need to create them first at !flexible.', array(
        '!entity_type' => $entity_type,
        '!bundle' => $bundle,
        '!view_mode' => $view_mode,
        '!flexible' => url('admin/structure/panels/layouts'),
      )) . '</p>' . panels_common_print_layout_links($layouts, $_GET['q'], array(
        'query' => $_GET,
      )),
    );

    // 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) {
      if ($row->entity_type == $entity_type && 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)) {
      $form['clone'] = array(
        '#title' => t('Clone layout from existing view mode'),
        '#type' => 'select',
        '#options' => $options,
      );
      $form['clone_submit'] = array(
        '#type' => 'submit',
        '#value' => t('Clone layout'),
        '#submit' => array(
          'ds_panels_layout_clone',
        ),
      );
    }
    return $form;
  }
  $form['ds_panels_layout']['info'] = array(
    '#markup' => '<p>' . t('Configure settings for the %layout layout.', array(
      '%layout' => $panel_layout,
    )) . '</p>',
  );

  // First time creation of a layout.
  if (!isset($ds_layout['settings']['did'])) {

    // Get the first region of the chosen layout.
    $chosen_layout = panels_get_layout($panel_layout);
    if (isset($chosen_layout['regions'])) {
      $form['ds_panels_layout']['add_default_fields'] = array(
        '#type' => 'checkbox',
        '#title' => t('Add default fields'),
        '#default_value' => TRUE,
      );
      $form['ds_panels_layout']['fields'] = array(
        '#type' => 'fieldset',
        '#title' => t('Default fields'),
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
        '#attributes' => array(
          'class' => array(
            'default-fallback',
          ),
        ),
        '#states' => array(
          'visible' => array(
            'input[name="add_default_fields"]' => array(
              'checked' => TRUE,
            ),
          ),
        ),
      );

      // Use prefix and suffixes to create a table here.
      $form['ds_panels_layout']['fields']['configure'] = array(
        '#prefix' => '<table id="ds-panels-layout-table"><th>' . t('Field') . '</th><th>' . t('Pane title') . '</th><th>' . t('Region') . '</th>',
        '#suffix' => '</table>',
      );
      $region_options = $chosen_layout['regions'];
      $region_keys = array_keys($chosen_layout['regions']);
      $i = 1;
      module_load_include('inc', 'field_ui', 'field_ui.admin');
      $fields = module_invoke_all('ds_panels_default_fields', $entity_type, $bundle, $view_mode);
      foreach ($fields as $field_name => $field) {
        $class = $i % 2 ? 'odd' : 'even';
        $form['ds_panels_layout']['fields']['configure'][$field_name . '_enable'] = array(
          '#type' => 'checkbox',
          '#title' => $field['label'],
          '#default_value' => TRUE,
          '#prefix' => '<tr class=' . $class . '><td>',
        );
        $form['ds_panels_layout']['fields']['configure'][$field_name . '_hide_title'] = array(
          '#type' => 'checkbox',
          '#title' => t('Hide'),
          '#default_value' => TRUE,
          '#prefix' => '</td><td>',
        );
        $form['ds_panels_layout']['fields']['configure'][$field_name . '_region'] = array(
          '#type' => 'select',
          '#options' => $region_options,
          '#default_value' => $region_keys[array_rand($region_keys)],
          '#prefix' => '</td><td>',
          '#suffix' => '</td></tr>',
        );
        $i++;
      }
    }
  }
  $form['ds_panels_layout']['layout'] = array(
    '#type' => 'value',
    '#value' => $panel_layout,
  );

  // Page title functionality, currently only works on nodes.
  if ($form['#entity_type'] == 'node' && ($form['#view_mode'] == 'full' || $form['#view_mode'] == 'revision' || variable_get('ds_extras_switch_view_mode', FALSE)) && variable_get('ds_extras_hide_page_title', FALSE)) {
    $form['ds_panels_layout']['ds_layouts']['ds_page_title_options'] = _ds_extras_page_title_options($ds_layout['settings'], $entity_type);
  }
  $form['ds_panels_layout']['css_id'] = array(
    '#type' => 'textfield',
    '#title' => t('CSS ID'),
    '#size' => 30,
    '#description' => t('An ID that can be used by CSS to style the panel.'),
    '#default_value' => isset($ds_layout['settings']['css_id']) ? $ds_layout['settings']['css_id'] : '',
  );
  $form['ds_panels_layout']['class'] = array(
    '#type' => 'textfield',
    '#title' => t('Classes'),
    '#size' => 30,
    '#description' => t('Add classes to the layout. Note that this will only work if the template has a $class variable.'),
    '#default_value' => isset($ds_layout['settings']['class']) ? $ds_layout['settings']['class'] : '',
  );
  if ($entity_type == 'node') {
    $form['ds_panels_layout']['sticky'] = array(
      '#type' => 'checkbox',
      '#title' => t('Add sticky class'),
      '#description' => t('Add a "sticky" class if a node is marked sticky. Only works if the template has a $class variable.'),
      '#default_value' => isset($ds_layout['settings']['sticky']) ? $ds_layout['settings']['sticky'] : '',
    );
  }
  else {
    $form['ds_panels_layout']['sticky'] = array(
      '#type' => 'value',
      '#value' => FALSE,
    );
  }
  $form['ds_panels_layout']['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($ds_layout['settings']['hide_sidebars']) ? $ds_layout['settings']['hide_sidebars'] : FALSE,
  );
  $form['ds_panels_layout']['actions']['save'] = array(
    '#type' => 'submit',
    '#value' => t('Save layout'),
    '#submit' => array(
      'ds_panels_layout_save',
    ),
  );
  if (isset($ds_layout['settings']['did'])) {
    $form['#did'] = $ds_layout['settings']['did'];
    $form['ds_panels_layout']['actions']['layout_change'] = array(
      '#type' => 'submit',
      '#value' => t('Change layout'),
      '#submit' => array(
        'ds_panels_layout_change',
      ),
    );
    $form['ds_panels_layout']['actions']['layout_remove'] = array(
      '#type' => 'submit',
      '#value' => t('Remove layout'),
      '#submit' => array(
        'ds_panels_layout_remove',
      ),
    );
  }

  // Check if we need to strip out the panel layout key.
  $form['#strip_off_layout_from_url'] = $layout_tab_first;

  // Add javascript.
  $form['#attached']['js'][] = drupal_get_path('module', 'ds_extras') . '/ds_extras.panels.admin.js';
  return $form;
}