node_edit_form.inc
Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 function panels_node_edit_form_panels_contexts() {
00012 $args['node_edit_form'] = array(
00013 'title' => t("Node edit form"),
00014 'description' => t('A node edit form.'),
00015 'context' => 'panels_context_create_node_edit_form',
00016 'settings form' => 'panels_context_node_edit_form_settings_form',
00017 'settings form validate' => 'panels_context_node_edit_form_settings_form_validate',
00018 'keyword' => 'node_edit',
00019 'context name' => 'node_edit_form',
00020 );
00021 return $args;
00022 }
00023
00024
00025
00026
00027
00028 function panels_context_create_node_edit_form($empty, $node = NULL, $conf = FALSE) {
00029 $context = new panels_context(array('form', 'node_edit', 'node_form', 'node'));
00030 $context->plugin = 'node_edit_form';
00031
00032 if ($empty) {
00033 return $context;
00034 }
00035
00036 if ($conf) {
00037
00038 $node = node_load($node['nid']);
00039 }
00040
00041 if (!empty($node) && node_access('update', $node)) {
00042
00043 if ($_POST['op'] == t('Delete')) {
00044
00045 if ($_REQUEST['destination']) {
00046 $destination = drupal_get_destination();
00047 unset($_REQUEST['destination']);
00048 }
00049 drupal_goto('node/'. $node->nid .'/delete', $destination);
00050 }
00051
00052 $form = drupal_retrieve_form($node->type . '_node_form', $node);
00053 drupal_process_form($node->type . '_node_form', $form);
00054
00055 $context->data = $node;
00056 $context->title = $node->title;
00057 $context->argument = $node->nid;
00058
00059 $context->form = $form;
00060 $context->form_id = $node->type . '_node_form';
00061 $context->form_title = $node->title;
00062 $context->node_type = $node->type;
00063 return $context;
00064 }
00065 }
00066
00067 function panels_context_node_edit_form_settings_form($conf, $external = FALSE) {
00068 if ($external) {
00069 $form['external'] = array(
00070 '#type' => 'checkbox',
00071 '#default_value' => $conf['external'],
00072 '#title' => t('Require this context from an external source (such as a containing panel page).'),
00073 '#description' => t('If selected, node selection (below) will be ignored.'),
00074 );
00075 }
00076
00077 $form['node'] = array(
00078 '#prefix' => '<div class="no-float">',
00079 '#suffix' => '</div>',
00080 '#title' => t('Enter the title or NID of a post'),
00081 '#type' => 'textfield',
00082 '#maxlength' => 512,
00083 '#autocomplete_path' => 'panels/node/autocomplete',
00084 '#weight' => -10,
00085 );
00086
00087 if (!empty($conf['nid'])) {
00088 $info = db_fetch_object(db_query("SELECT * FROM {node} WHERE nid = %d", $conf['nid']));
00089 if ($info) {
00090 $link = l("'$info->title' [node id: $info->nid]", "node/$info->nid", array('target' => '_blank', 'title' => t('Open in new window')));
00091 $form['node']['#description'] = t('Currently set to !link', array('!link' => $link));
00092 }
00093 }
00094
00095 $form['nid'] = array(
00096 '#type' => 'value',
00097 '#value' => $conf['nid'],
00098 );
00099
00100 $form['external'] = array(
00101 '#type' => 'value',
00102 '#value' => $external,
00103 );
00104
00105 return $form;
00106 }
00107
00108
00109
00110
00111 function panels_context_node_edit_form_settings_form_validate($form, $form_values) {
00112 if (empty($form_values['external']) && empty($form_values['nid']) && empty($form_values['node'])) {
00113 form_error($form['node'], t('You must select a node.'));
00114 return;
00115 }
00116
00117 if (empty($form_values['node'])) {
00118 return;
00119 }
00120
00121 if ($nid = panels_nid_autocomplete($form_values['node'])) {
00122 form_set_value($form['nid'], $nid);
00123 }
00124 else {
00125 form_error($form['node'], t('Invalid node selected.'));
00126 }
00127 }
00128