You are here

function panels_node_form in Panels 6.3

Same name and namespace in other branches
  1. 5.2 panels_node/panels_node.module \panels_node_form()
  2. 6.2 panels_node/panels_node.module \panels_node_form()

Implementation of hook_form().

File

panels_node/panels_node.module, line 134
panels_node.module

Code

function panels_node_form(&$node, &$param) {
  ctools_include('plugins', 'panels');
  $form['panels_node']['#tree'] = TRUE;
  if (empty($node->nid) && arg(0) == 'node' && arg(1) == 'add') {

    // Grab our selected layout from the $node, If it doesn't exist, try arg(3)
    // and if that doesn't work present them with a list to pick from.
    $panel_layout = isset($node->panel_layout) ? $node->panel_layout : arg(3);
    if (empty($panel_layout)) {
      $opts = $_GET;
      unset($opts['q']);
      return drupal_goto('node/add/panel/choose-layout', $opts);
    }
    $layout = panels_get_layout($panel_layout);
    if (empty($layout)) {
      return drupal_not_found();
    }
    $form['panels_node']['layout'] = array(
      '#type' => 'value',
      '#value' => $panel_layout,
    );
  }
  $type = node_get_types('type', $node);
  $form['title'] = array(
    '#type' => 'textfield',
    '#title' => check_plain($type->title_label),
    '#required' => TRUE,
    '#default_value' => $node->title,
  );
  if (!empty($type->body_label)) {
    $form['body_field']['#prefix'] = '<div class="body-field-wrapper">';
    $form['body_field']['#suffix'] = '</div>';
    $form['body_field']['body'] = array(
      '#type' => 'textarea',
      '#title' => check_plain($type->body_label),
      '#rows' => 10,
      '#required' => TRUE,
      '#description' => t('The teaser is a piece of text to describe when the panel is listed (such as when promoted to front page); the actual content will only be displayed on the full node view.'),
      '#default_value' => $node->body,
    );
    $form['body_field']['format'] = filter_form($node->format);

    // Now we can set the format!
  }

  //  drupal_set_message('<pre>' . check_plain(var_export($node, true)) . '</pre>');
  $css_id = '';
  if (!empty($node->panels_node['css_id'])) {
    $css_id = $node->panels_node['css_id'];
  }
  $form['panels_node']['css_id'] = array(
    '#type' => 'textfield',
    '#title' => t('CSS ID'),
    '#size' => 30,
    '#description' => t('An ID that can be used by CSS to style the panel.'),
    '#default_value' => $css_id,
  );

  // Support for different rendering pipelines
  // Mostly borrowed from panel_context.inc
  $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['panels_node']['pipeline'] = array(
      '#type' => 'value',
      '#value' => $node->panels_node['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['panels_node']['pipeline'] = array(
      '#type' => 'radios',
      '#options' => $options,
      '#title' => t('Renderer'),
      '#default_value' => !empty($node->panels_node['pipeline']) ? $node->panels_node['pipeline'] : 'standard',
    );
  }
  return $form;
}