You are here

function panels_edit_layout_settings_form in Panels 6.2

Same name and namespace in other branches
  1. 5.2 includes/display_edit.inc \panels_edit_layout_settings_form()

Form definition for the display layout settings editor.

See also

panels_edit_layout_settings_form_validate()

panels_edit_layout_settings_form_submit()

1 string reference to 'panels_edit_layout_settings_form'
_panels_edit_layout_settings in includes/display-layout-settings.inc
Handle calling and processing of the form for editing display layout settings.

File

includes/display-layout-settings.inc, line 51
Form and ajax handling for edit layout settings

Code

function panels_edit_layout_settings_form(&$form_state) {
  $form = array();
  $display =& $form_state['display'];

  // Style settings are edited via a modal and cached, this will retrieve
  // them from cache if posting or insert them into cache if the form is
  // being filled out fresh.
  if (!empty($_POST) && is_array($cache = panels_cache_get('style_settings', $display->did))) {
    $display->panel_settings['style_settings'] = $cache;
  }
  else {
    if (!isset($display->panel_settings['style_settings'])) {
      $display->panel_settings['style_settings'] = array();
    }
    panels_cache_set('style_settings', $display->did, $display->panel_settings['style_settings']);
  }
  $layout = panels_get_layout($display->layout);

  // TODO doc the ability to do this as part of the API
  if (!empty($layout['settings form']) && function_exists($layout['settings form'])) {
    $form['layout_settings'] = $layout['settings form']($display, $layout, $display->layout_settings);
  }
  $form['layout_settings']['#tree'] = TRUE;
  if ($form_state['display_title']) {
    $form['display_title'] = array(
      '#type' => 'fieldset',
      '#title' => t('Panel title'),
      '#tree' => TRUE,
    );
    $form['display_title']['title'] = array(
      '#type' => 'textfield',
      '#size' => 35,
      '#default_value' => $display->title,
      '#title' => t('Title'),
      '#description' => t('The title of this panel. Your theme will render this text as the main page title users view this display, unless this text is overridden elsewhere.'),
    );
    $form['display_title']['hide_title'] = array(
      '#type' => 'checkbox',
      '#title' => t('Hide title'),
      '#default_value' => $display->hide_title,
      '#description' => t('Check this box to hide the main page title for this panel.'),
    );
    if (isset($title) && is_string($title)) {
      $form['display_title']['title']['#description'] .= " " . t("If you leave this field blank, then the default title, '@title', will be used instead.", array(
        '@title' => $title,
      ));
    }
  }
  $panel_settings = $display->panel_settings;
  $style = panels_get_style(!empty($panel_settings['style']) ? $panel_settings['style'] : 'default');

  // Let the user choose between panel styles that are available for any
  // panels implementation or specifically to this one.
  $options = array();
  foreach (panels_get_styles() as $name => $properties) {
    if (empty($properties['hidden']) && !empty($properties['render panel'])) {
      $options[$name] = $properties['title'];
    }
  }
  $form['panel_settings'] = array(
    '#type' => 'fieldset',
    '#title' => t('Panel settings'),
    '#tree' => TRUE,
  );
  $form['panel_settings']['start_box'] = array(
    '#value' => '<div class="form-item clear-block"><label>' . t('Default panel style') . ':</label>',
  );

  // component #1 of the URL for hte panel style settings button.
  $form['panel_settings']['edit_style_destination'] = array(
    '#attributes' => array(
      'class' => 'panels-style-settings-url',
    ),
    '#type' => 'hidden',
    '#value' => url('panels/ajax/style-settings/' . $display->did . '/default', array(
      'absolute' => true,
    )),
  );

  // Component #2 of the URL -- the value will be selected by the user.
  $form['panel_settings']['style'] = array(
    '#prefix' => '<div class="panels-style-settings-box">',
    '#suffix' => '</div>',
    '#type' => 'select',
    '#options' => $options,
    '#attributes' => array(
      'class' => 'panels-style-settings-url',
    ),
    '#default_value' => $style['name'],
  );

  // Is this form being posted? If so, check cache.
  $style_settings = $panel_settings['style_settings'];
  $form['panel_settings']['style_settings'] = array(
    '#type' => 'value',
    '#value' => $style_settings,
  );
  $form['panel_settings']['edit_style'] = array(
    '#type' => 'submit',
    '#attributes' => array(
      'class' => 'panels-ajax-link',
    ),
    '#id' => 'panels-style-settings',
    '#value' => t('Edit style settings'),
  );
  $form['panel_settings']['end_box'] = array(
    '#value' => '</div>',
  );
  $form['panel_settings']['individual'] = array(
    '#type' => 'checkbox',
    '#title' => t('Per panel settings'),
    '#id' => 'panel-settings-individual',
    '#description' => t('If this is checked, each region in the display can have its own style.'),
    '#default_value' => !empty($panel_settings['individual']),
  );
  $layout_options = array_merge(array(
    '-1' => t('Use the default panel style'),
  ), $options);
  $layout_panels = panels_get_panels($layout, $display);
  $checkboxes = array();
  foreach ($layout_panels as $id => $name) {
    $form['panel_settings']['panel'][$id]['start_box'] = array(
      '#value' => '<div class="form-item clear-block"><label>' . $name . ':</label>',
    );

    // component #1 of the URL for hte panel style settings button.
    $form['panel_settings']['panel'][$id]['edit_style_destination'] = array(
      '#attributes' => array(
        'class' => "panels-style-settings-{$id}-url",
      ),
      '#type' => 'hidden',
      '#value' => url('panels/ajax/style-settings/' . $display->did . '/' . $id, array(
        'absolute' => true,
      )),
    );
    if (!isset($display->panel_settings['panel'][$id]['style'])) {
      $display->panel_settings['panel'][$id]['style'] = -1;
    }

    // Component #2 of the URL -- the value will be selected by the user.
    $form['panel_settings']['panel'][$id]['style'] = array(
      '#prefix' => '<div class="panels-style-settings-box">',
      '#suffix' => '</div>',
      '#type' => 'select',
      '#options' => $layout_options,
      '#id' => 'panel-settings-style-' . $id,
      '#attributes' => array(
        'class' => "panels-style-settings-{$id}-url",
      ),
      '#default_value' => $display->panel_settings['panel'][$id]['style'],
    );
    $checkboxes[] = '#panel-settings-style-' . $id;
    $form['panel_settings']['panel'][$id]['edit_style'] = array(
      '#type' => 'submit',
      '#id' => 'panels-style-settings-' . $id,
      '#attributes' => array(
        'class' => 'panels-ajax-link',
      ),
      '#value' => t('Edit style settings'),
    );
    $checkboxes[] = '#panels-style-settings-' . $id;
    $form['panel_settings']['panel'][$id]['end_box'] = array(
      '#value' => '</div>',
    );
  }
  $form_state['layout'] = $layout;

  // Always show a Save button even if they sent in a Next or something similar
  // button.
  if ($form_state['finish'] !== t('Save')) {
    $form['save'] = array(
      '#type' => 'submit',
      '#value' => t('Save'),
      '#return_here' => TRUE,
    );
  }
  if (empty($form_state['no buttons'])) {
    $form['submit'] = array(
      '#type' => 'submit',
      '#value' => $form_state['finish'],
    );
  }
  panels_modal_js_includes();

  // @todo -- why dnd? That's wrong.
  drupal_add_css(panels_get_path('css/panels_dnd.css'));
  $settings['panels']['checkboxes']['#panel-settings-individual'] = $checkboxes;
  drupal_add_js($settings, 'setting');
  return $form;
}