You are here

function panels_common_settings in Panels 6.3

Same name and namespace in other branches
  1. 5.2 includes/common.inc \panels_common_settings()
  2. 6.2 includes/common.inc \panels_common_settings()
  3. 7.3 includes/common.inc \panels_common_settings()

A common settings page for Panels modules, because this code is relevant to any modules that don't already have special requirements.

3 string references to 'panels_common_settings'
panels_admin_panel_context_page in includes/callbacks.inc
Settings for panel contexts created by the page manager.
panels_mini_settings in panels_mini/panels_mini.admin.inc
Settings for mini panels.
panels_node_settings in panels_node/panels_node.module
Settings for panel nodes.

File

includes/common.inc, line 226
Functions used by more than one panels client module.

Code

function panels_common_settings(&$form_state, $module_name = 'panels_common') {
  ctools_include('plugins', 'panels');
  ctools_include('content');
  $content_types = ctools_get_content_types();
  $skip = FALSE;
  $default_types = variable_get($module_name . '_default', NULL);
  if (!isset($default_types)) {
    $default_types = array(
      'other' => TRUE,
    );
    $skip = TRUE;
  }
  foreach ($content_types as $id => $info) {
    if (empty($info['single'])) {
      $default_options[$id] = t('New @s', array(
        '@s' => $info['title'],
      ));
      if ($skip) {
        $default_types[$id] = TRUE;
      }
    }
  }
  $default_options['other'] = t('New content of other types');
  $form['panels_common_default'] = array(
    '#type' => 'checkboxes',
    '#title' => t('New content behavior'),
    '#description' => t('Select the default behavior of new content added to the system. If checked, new content will automatically be immediately available to be added to Panels pages. If not checked, new content will not be available until specifically allowed here.'),
    '#options' => $default_options,
    '#default_value' => array_keys(array_filter($default_types)),
  );
  $form_state['skip'] = $skip;
  if ($skip) {
    $form['markup'] = array(
      '#value' => t('<p>Click Submit to be presented with a complete list of available content types set to the defaults you selected.</p>'),
    );
  }
  else {

    // Rebuild the entire list, setting appropriately from defaults. Give
    // each type its own checkboxes set unless it's 'single' in which
    // case it can go into our fake other set.
    $available_content_types = ctools_content_get_all_types();
    $allowed_content_types = variable_get($module_name . '_allowed_types', array());
    foreach ($available_content_types as $id => $types) {
      foreach ($types as $type => $info) {
        $key = $id . '-' . $type;
        $checkboxes = empty($content_types[$id]['single']) ? $id : 'other';
        $options[$checkboxes][$key] = $info['title'];
        if (!isset($allowed_content_types[$key])) {
          $allowed[$checkboxes][$key] = isset($default_types[$id]) ? $default_types[$id] : $default_types['other'];
        }
        else {
          $allowed[$checkboxes][$key] = $allowed_content_types[$key];
        }
      }
    }
    $form['content_types'] = array(
      '#tree' => TRUE,
      '#prefix' => '<div class="clear-block">',
      '#suffix' => '</div>',
    );

    // cheat a bit
    $content_types['other'] = array(
      'title' => t('Other'),
      'weight' => 10,
    );
    foreach ($content_types as $id => $info) {
      if (isset($allowed[$id])) {
        $form['content_types'][$id] = array(
          '#prefix' => '<div class="panels-page-type-container">',
          '#suffix' => '</div>',
          '#type' => 'checkboxes',
          '#title' => t('Allowed @s content', array(
            '@s' => $info['title'],
          )),
          '#options' => $options[$id],
          '#default_value' => array_keys(array_filter($allowed[$id])),
          '#checkall' => TRUE,
        );
      }
    }
  }
  panels_common_allowed_layouts_form($form, $form_state, $module_name);
  $form['module_name'] = array(
    '#type' => 'value',
    '#value' => $module_name,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  ctools_add_css('panels_page', 'panels');
  return $form;
}