You are here

function panels_common_settings in Panels 5.2

Same name and namespace in other branches
  1. 6.3 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_mini_settings in panels_mini/panels_mini.module
Settings for mini panels.
panels_node_settings in panels_node/panels_node.module
Settings for panel nodes.
panels_page_settings in panels_page/panels_page.module
Settings for panel pages.

File

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

Code

function panels_common_settings($module_name = 'panels_common') {
  panels_load_include('plugins');
  $content_types = panels_get_content_types();
  $default_types = variable_get($module_name . '_default', NULL);
  if (!isset($default_types)) {
    $default_types = array(
      'block' => TRUE,
      'views' => TRUE,
      'other' => TRUE,
    );
    $skip = TRUE;
  }
  foreach ($content_types as $id => $info) {
    if (empty($info['single'])) {
      $default_options[$id] = t('New @s', array(
        '@s' => $info['title'],
      ));
    }
  }
  $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)),
  );
  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>'),
    );
    $form['skip'] = array(
      '#type' => 'value',
      '#value' => TRUE,
    );
  }
  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 = panels_get_all_content_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,
    );

    // 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 clear-block">',
          '#suffix' => '</div>',
          '#type' => 'checkboxes',
          '#title' => t('Allowed @s content', array(
            '@s' => $info['title'],
          )),
          '#options' => $options[$id],
          '#default_value' => array_keys(array_filter($allowed[$id])),
        );
      }
    }
  }
  $form['module_name'] = array(
    '#type' => 'value',
    '#value' => $module_name,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),
  );
  drupal_add_css(panels_get_path('css/panels_page.css'));
  return $form;
}