You are here

function panels_panel_settings in Panels 5.2

Form to edit panel style settings.

1 call to panels_panel_settings()
panels_edit_layout_settings_form in includes/display_edit.inc
Form definition for the display layout settings editor.

File

includes/display_edit.inc, line 1418

Code

function panels_panel_settings($display) {
  $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 = array();
  $form['display'] = array(
    '#type' => 'value',
    '#value' => $display,
  );
  $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>',
  );
  $modals = array();
  $form['panel_settings']['style'] = array(
    '#prefix' => '<div class="panels-style-settings-box">',
    '#suffix' => '</div>',
    '#type' => 'select',
    '#options' => $options,
    '#id' => 'panel-settings-style',
    '#default_value' => $style['name'],
  );

  // Is this form being posted? If so, check cache.
  if (!empty($_POST)) {
    $style_settings = panels_common_cache_get('style_settings', $display->did);
  }
  if (!isset($style_settings)) {
    $style_settings = !empty($panel_settings['style_settings']) ? $panel_settings['style_settings'] : array();
    panels_common_cache_set('style_settings', $display->did, $style_settings);
  }
  $form['panel_settings']['style_settings'] = array(
    '#type' => 'value',
    '#value' => $style_settings,
  );
  $form['panel_settings']['edit_style'] = array(
    '#type' => 'submit',
    '#id' => 'panels-style-settings',
    '#value' => t('Edit style settings'),
  );

  // Set up the AJAX settings for the modal.
  $modals['#panels-style-settings'] = array(
    url('panels/ajax/panel_settings/' . $display->did . '/default', NULL, NULL, TRUE),
    '#panel-settings-style',
  );
  $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' => $panel_settings['individual'],
  );
  $layout_options = array_merge(array(
    '-1' => t('Use the default panel style'),
  ), $options);
  $layout = panels_get_layout($display->layout);
  $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>',
    );
    $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,
      '#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-style-settings',
      ),
      '#value' => t('Edit style settings'),
    );
    $checkboxes[] = '#panels-style-settings-' . $id;

    // Set up the AJAX settings for the modal.
    $modals['#panels-style-settings-' . $id] = array(
      url('panels/ajax/panel_settings/' . $display->did . '/' . $id, NULL, NULL, TRUE),
      '#panel-settings-style-' . $id,
    );
    $form['panel_settings']['panel'][$id]['end_box'] = array(
      '#value' => '</div>',
    );
  }

  // while we don't use this directly some of our forms do.
  drupal_add_js('misc/collapse.js');
  drupal_add_js('misc/autocomplete.js');
  $ajax = array(
    'panels' => array(
      'closeText' => t('Close Window'),
      'closeImage' => theme('image', panels_get_path('images/icon-delete.png'), t('Close window'), t('Close window')),
      'throbber' => theme('image', panels_get_path('images/throbber.gif'), t('Loading...'), t('Loading')),
      'checkboxes' => array(
        '#panel-settings-individual' => $checkboxes,
      ),
      'modals' => $modals,
    ),
  );
  $form['panel_settings']['did'] = array(
    '#type' => 'value',
    '#value' => $display->did,
  );
  drupal_add_js(panels_get_path('js/lib/dimensions.js'));
  drupal_add_js(panels_get_path('js/lib/mc.js'));
  drupal_add_js(panels_get_path('js/lib/form.js'));
  drupal_add_js($ajax, 'setting');
  drupal_add_js(panels_get_path('js/checkboxes.js'));
  drupal_add_js(panels_get_path('js/modal_forms.js'));
  drupal_add_css(panels_get_path('css/panels_dnd.css'));
  return $form;
}