You are here

function context_admin_node_add_wrapper in Contextual Administration 7

Build our own node_add style function so that we can do things core does not support. Also, we need to call a completely different form so that we can load the node.pages.inc file from drupal_get_form so that ajax fields continue to work.

4 calls to context_admin_node_add_wrapper()
context_admin_entityref_create_node_render_page in plugins/context_admin/entityref_create_node.inc
context_admin_noderef_create_node_render_page in plugins/context_admin/noderef_create_node.inc
context_admin_node_create_menu_render_page in plugins/context_admin/node_create_menu.inc
context_admin_termref_create_node_render_page in plugins/context_admin/termref_create_node.inc

File

./context_admin.module, line 217

Code

function context_admin_node_add_wrapper($type, $fields = array(), $use_panels = FALSE) {
  global $user;
  $types = node_type_get_types();
  $node = new stdClass();
  $fields += array(
    'uid' => $user->uid,
    'name' => isset($user->name) ? $user->name : '',
    'type' => $type,
    'language' => LANGUAGE_NONE,
  );
  foreach ($fields as $field_id => $value) {
    if (is_array($value)) {
      foreach ($value['values'] as $field_value) {
        $node->{$field_id}[$value['language']][][$value['key']] = $field_value;
      }
    }
    else {
      $node->{$field_id} = $value;
    }
  }
  if ($use_panels && module_exists('panels')) {

    // Render form using Page Manager's node/%node/edit page
    // Requires node/%node/edit page to be enabled.  Check for this and disable checkbox above?  FIXME
    ctools_include("plugins");
    $plugin = ctools_get_plugins("page_manager", "tasks", "node_edit");
    global $user;
    drupal_set_title(t('Create @name', array(
      '@name' => $types[$type]->name,
    )));
    return page_manager_node_edit($node);
  }
  drupal_set_title(t('Create @name', array(
    '@name' => $types[$type]->name,
  )), PASS_THROUGH);
  $page = page_manager_get_current_page();
  return drupal_get_form('context_admin_node_form_wrapper', $node, $page);
}