You are here

function ctools_context_create_node_edit_form in Chaos Tool Suite (ctools) 6

Same name and namespace in other branches
  1. 7 plugins/contexts/node_edit_form.inc \ctools_context_create_node_edit_form()

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

1 string reference to 'ctools_context_create_node_edit_form'
node_edit_form.inc in plugins/contexts/node_edit_form.inc
Plugin to provide a node_edit_form context

File

plugins/contexts/node_edit_form.inc, line 36
Plugin to provide a node_edit_form context

Code

function ctools_context_create_node_edit_form($empty, $node = NULL, $conf = FALSE) {
  static $creating = FALSE;
  $context = new ctools_context(array(
    'form',
    'node_edit',
    'node_form',
    'node',
    'node_edit_form',
  ));
  $context->plugin = 'node_edit_form';
  if ($empty || $creating) {
    return $context;
  }
  $creating = TRUE;
  if ($conf) {

    // In this case, $node is actually our $conf array.
    $nid = is_array($node) && isset($node['nid']) ? $node['nid'] : (is_object($node) ? $node->nid : 0);
    if (module_exists('translation')) {
      if ($translation = module_invoke('translation', 'node_nid', $nid, $GLOBALS['language']->language)) {
        $nid = $translation;
        $reload = TRUE;
      }
    }
    if (is_array($node) || !empty($reload)) {
      $node = node_load($nid);
    }
  }
  if (!empty($node)) {
    ctools_include('form');
    $form_id = $node->type . '_node_form';
    $form_state = array(
      'want form' => TRUE,
      'args' => array(
        $node,
      ),
    );
    $file = drupal_get_path('module', 'node') . '/node.pages.inc';
    include_once './' . $file;

    // This piece of information can let other modules know that more files
    // need to be included if this form is loaded from cache:
    $form_state['form_load_files'] = array(
      $file,
    );
    $form = ctools_build_form($form_id, $form_state);

    // Fill in the 'node' portion of the context
    $context->data = $node;
    $context->title = $node->title;
    $context->argument = isset($node->nid) ? $node->nid : $node->type;
    $context->form = $form;
    $context->form_state =& $form_state;
    $context->form_id = $form_id;
    $context->form_title = $node->title;
    $context->node_type = $node->type;
    $context->restrictions['type'] = array(
      $node->type,
    );
    $context->restrictions['form'] = array(
      'form',
    );
    $creating = FALSE;
    return $context;
  }
  $creating = FALSE;
}