You are here

common.inc in Panelizer 6

Same filename and directory in other branches
  1. 7.3 includes/common.inc
  2. 7 includes/common.inc
  3. 7.2 includes/common.inc

Contains common forms and routines that different object types use.

The panelizer system has several different places that panels can be edited. While they are all subtly different, they have a lot in common.

File

includes/common.inc
View source
<?php

/**
 * @file
 * Contains common forms and routines that different object types use.
 *
 * The panelizer system has several different places that panels can be
 * edited. While they are all subtly different, they have a lot in common.
 */

/**
 * Form to configure basic panelizer settings.
 *
 * This form has *no* knowledge of what is being panelized. It can be a
 * node or a user. Therefore it doesn't provide its own submit handlers.
 * The caller needs to do that.
 */
function panelizer_settings_form(&$form_state) {
  $panelizer = $form_state['panelizer'];
  $form['no_blocks'] = array(
    '#type' => 'checkbox',
    '#default_value' => $panelizer->no_blocks,
    '#title' => t('Disable Drupal blocks/regions'),
    '#description' => t('Check this to have the panel disable sidebars displayed in the theme. Note that some themes support this setting better than others. If in doubt, try with stock themes to see.'),
  );
  ctools_include('plugins', 'panels');
  $pipelines = panels_get_renderer_pipelines();

  // If there are no pipelines, that probably means we're operating in
  // legacy mode.
  if (empty($pipelines)) {

    // We retain the original pipeline so we don't wreck things by installing
    // old modules.
    $form['pipeline'] = array(
      '#type' => 'value',
      '#value' => $panelizer->pipeline,
    );
  }
  else {
    $options = array();
    foreach ($pipelines as $name => $pipeline) {
      $options[$name] = check_plain($pipeline->admin_title) . '<div class="description">' . check_plain($pipeline->admin_description) . '</div>';
    }
    $form['pipeline'] = array(
      '#type' => 'radios',
      '#options' => $options,
      '#title' => t('Renderer'),
      '#default_value' => $panelizer->pipeline,
    );
  }
  $form['css_id'] = array(
    '#type' => 'textfield',
    '#size' => 35,
    '#default_value' => $panelizer->css_id,
    '#title' => t('CSS ID'),
    '#description' => t('The CSS ID to apply to this panel'),
  );
  $form['css'] = array(
    '#type' => 'textarea',
    '#title' => t('CSS code'),
    '#description' => t('Enter well-formed CSS code here; this code will be embedded into the panel, and should only be used for minor adjustments; it is usually better to try to put CSS for the panel into the theme if possible. This CSS will be filtered for safety so some CSS may not work.'),
    '#default_value' => $panelizer->css,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  if (!empty($form_state['reset button'])) {
    $form['reset'] = array(
      '#type' => 'submit',
      '#value' => t('Reset to default'),
      '#reset' => TRUE,
    );
  }
  return $form;
}

/**
 * Submit callback
 */
function panelizer_settings_form_submit(&$form, &$form_state) {
  $panelizer =& $form_state['panelizer'];
  $panelizer->no_blocks = $form_state['values']['no_blocks'];
  $panelizer->css = $form_state['values']['css'];
  $panelizer->css_id = $form_state['values']['css_id'];
  $panelizer->pipeline = $form_state['values']['pipeline'];
}

/**
 * Form to edit contexts that go with a panelizer panel.
 */
function panelizer_default_context_form(&$form_state) {
  $form = array();
  ctools_include('context-admin');
  ctools_context_admin_includes();
  $panelizer =& $form_state['panelizer'];
  $panelizer->base_contexts = panelizer_get_base_context($form_state['panelizer id']);
  if (!empty($panelizer->cached)) {
    $form['markup'] = array(
      '#prefix' => '<div class="messages warning">',
      '#value' => t('This form contains unsaved changes that will not be stored until the Save button is clicked.'),
      '#suffix' => '</div>',
    );
  }
  $form['right'] = array(
    '#prefix' => '<div class="clear-block"><div class="right-container">',
    '#suffix' => '</div>',
  );
  $form['left'] = array(
    '#prefix' => '<div class="left-container">',
    '#suffix' => '</div></div>',
  );
  $module = 'panelizer-' . $form_state['panelizer type'];
  ctools_context_add_context_form($module, $form, $form_state, $form['right']['contexts_table'], $panelizer, $form_state['cache key']);
  ctools_context_add_relationship_form($module, $form, $form_state, $form['right']['relationships_table'], $panelizer, $form_state['cache key']);

  // Set an additional description if CCK and Token are enabled, to notify of unlisted keywords
  if (module_exists('content') && module_exists('token')) {
    $description = t('Note that CCK fields may be used as keywords using patterns like <em>%node:field_name-formatted</em>.');
  }
  elseif (!module_exists('token')) {
    $description = t('More keywords will be available if you install the Token module, see http://drupal.org/project/token.');
  }
  else {
    $description = '';
  }
  $form['left']['summary'] = array(
    '#prefix' => '<div class="page-manager-contexts">',
    '#suffix' => '</div>',
    '#value' => theme('ctools_context_list', $panelizer, t('Summary of contexts'), $description),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
    '#write' => TRUE,
  );
  $form['cancel'] = array(
    '#type' => 'submit',
    '#value' => t('Cancel'),
  );
  return $form;
}

Functions

Namesort descending Description
panelizer_default_context_form Form to edit contexts that go with a panelizer panel.
panelizer_settings_form Form to configure basic panelizer settings.
panelizer_settings_form_submit Submit callback