6 * @file contexts/node_edit_form.inc
8 * Plugin to provide a node_edit_form context
11 function panels_node_edit_form_panels_contexts() {
12 $args['node_edit_form'] = array(
13 'title' => t("Node edit form"),
14 'description' => t('A node edit form.'),
15 'context' => 'panels_context_create_node_edit_form',
16 'settings form' => 'panels_context_node_edit_form_settings_form',
17 'settings form validate' => 'panels_context_node_edit_form_settings_form_validate',
18 'keyword' => 'node_edit',
19 'context name' => 'node_edit_form',
25 * It's important to remember that $conf is optional here, because contexts
26 * are not always created from the UI.
28 function panels_context_create_node_edit_form($empty, $node = NULL
, $conf = FALSE
) {
29 $context = new
panels_context(array('form', 'node_edit', 'node_form', 'node'));
30 $context->plugin
= 'node_edit_form';
37 // In this case, $node is actually our $conf array.
38 $node = node_load($node['nid']);
41 if (!empty($node) && node_access('update', $node)) {
42 // This is from node_edit_page cause Drupal still doesn't use fapi right.
43 if ($_POST['op'] == t('Delete')) {
44 // Note: we redirect from node/nid/edit to node/nid/delete to make the tabs disappear.
45 if ($_REQUEST['destination']) {
46 $destination = drupal_get_destination();
47 unset($_REQUEST['destination']);
49 drupal_goto('node/'.
$node->nid .
'/delete', $destination);
52 $form = drupal_retrieve_form($node->type .
'_node_form', $node);
53 drupal_process_form($node->type .
'_node_form', $form);
54 // Fill in the 'node' portion of the context
55 $context->data
= $node;
56 $context->title
= $node->title
;
57 $context->argument
= $node->nid
;
59 $context->form
= $form;
60 $context->form_id
= $node->type .
'_node_form';
61 $context->form_title
= $node->title
;
62 $context->node_type
= $node->type
;
67 function panels_context_node_edit_form_settings_form($conf, $external = FALSE
) {
69 $form['external'] = array(
70 '#type' => 'checkbox',
71 '#default_value' => $conf['external'],
72 '#title' => t('Require this context from an external source (such as a containing panel page).'),
73 '#description' => t('If selected, node selection (below) will be ignored.'),
77 $form['node'] = array(
78 '#prefix' => '<div class="no-float">',
79 '#suffix' => '</div>',
80 '#title' => t('Enter the title or NID of a post'),
81 '#type' => 'textfield',
83 '#autocomplete_path' => 'panels/node/autocomplete',
87 if (!empty($conf['nid'])) {
88 $info = db_fetch_object(db_query("SELECT * FROM {node} WHERE nid = %d", $conf['nid']));
90 $link = l(t("'%title' [node id %nid]", array('%title' => $info->title
, '%nid' => $info->nid
)), "node/$info->nid", array('target' => '_blank', 'title' => t('Open in new window')));
91 $form['node']['#description'] = t('Currently set to !link', array('!link' => $link));
97 '#value' => $conf['nid'],
100 $form['external'] = array(
102 '#value' => $external,
111 function panels_context_node_edit_form_settings_form_validate($form, &$form_values, &$form_state) {
112 if (empty($form_values['external']) && empty($form_values['nid']) && empty($form_values['node'])) {
113 form_error($form['node'], t('You must select a node.'));
117 if (empty($form_values['node'])) {
121 $nid = $form_values['node'];
122 if (is_numeric($nid)) {
123 $node = db_fetch_object(db_query(db_rewrite_sql("SELECT n.nid FROM {node} n WHERE n.nid = %d"), $nid));
126 $node = db_fetch_object(db_query(db_rewrite_sql("SELECT n.nid FROM {node} n WHERE LOWER(n.title) = LOWER('%s')"), $nid));
128 form_set_value($form['nid'], $node->nid
, $form_state);
133 form_error($form['node'], t('Invalid node selected.'));