You are here

function panels_context_create_node_add_form in Panels 6.2

Same name and namespace in other branches
  1. 5.2 contexts/node_add_form.inc \panels_context_create_node_add_form()

It's important to remember that $conf is optional here, because contexts are not always created from the UI.

1 string reference to 'panels_context_create_node_add_form'
panels_node_add_form_panels_contexts in contexts/node_add_form.inc
@file contexts/node_add_form.inc

File

contexts/node_add_form.inc, line 26
contexts/node_add_form.inc

Code

function panels_context_create_node_add_form($empty, $data = NULL, $conf = FALSE) {
  $context = new panels_context(array(
    'form',
    'node_add',
    'node_form',
  ));
  $context->plugin = 'node_add_form';
  if ($empty) {
    return $context;
  }
  if ($conf) {
    $data = $data['type'];
  }
  if (!empty($data)) {
    $types = node_get_types();
    $type = str_replace('-', '_', $data);

    // Validate the node type exists.
    if (isset($types[$type]) && node_access('create', $type)) {

      // Initialize settings:
      global $user;
      $node = array(
        'uid' => $user->uid,
        'name' => $user->name,
        'type' => $type,
      );
      $form = drupal_retrieve_form($type . '_node_form', $node);
      drupal_process_form($type . '_node_form', $form);

      // In a form, $data is the object being edited.
      $context->data = $type;
      $context->title = $types[$type]->name;
      $context->argument = $type;

      // These are specific pieces of data to this form.
      // All forms should place the form here.
      $context->form = $form;
      $context->form_id = $type . '_node_form';
      $context->form_title = t('Submit @name', array(
        '@name' => $types[$type]->name,
      ));
      $context->node_type = $type;
      return $context;
    }
  }
}