node.inc File Reference

(1.1.2.16 2008/08/03 04:23:11 sdboyer)


Detailed Description

Plugin to provide a node context

Definition in file node.inc.

Go to the source code of this file.

Functions

 panels_context_create_node ($empty, $data=NULL, $conf=FALSE)
 panels_context_node_settings_form ($conf, $external=FALSE)
 panels_context_node_settings_form_validate ($form, $form_values)
 panels_node_panels_contexts ()


Function Documentation

panels_context_create_node ( empty,
data = NULL,
conf = FALSE 
)

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

Definition at line 28 of file node.inc.

00028                                                                          {
00029   $types = array('node');
00030   if (!empty($conf['types'])) {
00031     foreach ($conf['types'] as $type) {
00032       if ($type) {
00033         $types[] = 'node-' . $type;
00034       }
00035     }
00036   }
00037   $context = new panels_context($types);
00038   $context->plugin = 'node';
00039 
00040   if ($empty) {
00041     return $context;
00042   }
00043 
00044   if ($conf) {
00045     $nid = is_array($data) ? $data['nid'] : $data->nid;
00046 
00047     if (module_exists('translation')) {
00048        if ($translation = module_invoke('translation', 'node_nid', $nid, $GLOBALS['locale'])) {
00049         $nid = $translation;
00050         $reload = TRUE;
00051       }
00052     }
00053     
00054     if (is_array($data) || !empty($reload)) {
00055       $data = node_load($nid);
00056     }
00057   }
00058 
00059   if (!empty($data)) {
00060     $context->data     = $data;
00061     $context->title    = $data->title;
00062     $context->argument = $data->nid;
00063     if (is_array($context->type)) {
00064       $context->type[] = 'node-' . $data->type;
00065     }
00066     else {
00067       $context->type = array($context->type, 'node-' . $data->type);
00068     }
00069     return $context;
00070   }
00071 }

panels_context_node_settings_form ( conf,
external = FALSE 
)

Definition at line 73 of file node.inc.

00073                                                                      {
00074   if ($external) {
00075     $form['external'] = array(
00076       '#type' => 'checkbox',
00077       '#default_value' => $conf['external'],
00078       '#title' => t('Require this context from an external source (such as a containing panel page).'),
00079       '#description' => t('If selected, node selection (below) will be ignored.'),
00080     );
00081   }
00082 
00083 
00084   $form['node'] = array(
00085     '#prefix' => '<div class="no-float">',
00086     '#suffix' => '</div>',
00087     '#title' => t('Enter the title or NID of a post'),
00088     '#type' => 'textfield',
00089     '#maxlength' => 512,
00090     '#autocomplete_path' => 'panels/node/autocomplete',
00091     '#weight' => -10,
00092   );
00093 
00094   if (!empty($conf['nid'])) {
00095     $info = db_fetch_object(db_query("SELECT * FROM {node} n WHERE n.nid = %d", $conf['nid']));
00096     if ($info) {
00097       $link = l("'$info->title' [node id: $info->nid]", "node/$info->nid", array('target' => '_blank', 'title' => t('Open in new window')));
00098       $form['node']['#description'] = t('Currently set to !link', array('!link' => $link));
00099     }
00100   }
00101 
00102   $form['nid'] = array(
00103     '#type' => 'value',
00104     '#value' => $conf['nid'],
00105   );
00106 
00107   return $form;
00108 }

panels_context_node_settings_form_validate ( form,
form_values 
)

Validate a node.

Definition at line 113 of file node.inc.

References panels_nid_autocomplete().

00113                                                                          {
00114   // Validate the autocomplete
00115   if (empty($form_values['external']) && empty($form_values['nid']) && empty($form_values['node'])) {
00116     form_error($form['node'], t('You must select a node.'));
00117     return;
00118   }
00119 
00120   if (empty($form_values['node'])) {
00121     return;
00122   }
00123 
00124   if ($nid = panels_nid_autocomplete($form_values['node'])) {
00125     form_set_value($form['nid'], $nid);
00126   }
00127   else {
00128     form_error($form['node'], t('Invalid node selected.'));
00129   }
00130 }

Here is the call graph for this function:

panels_node_panels_contexts (  ) 

Definition at line 11 of file node.inc.

00011                                        {
00012   $args['node'] = array(
00013     'title' => t("Node"),
00014     'description' => t('A node object.'),
00015     'context' => 'panels_context_create_node',
00016     'settings form' => 'panels_context_node_settings_form',
00017     'settings form validate' => 'panels_context_node_settings_form_validate',
00018     'keyword' => 'node',
00019     'context name' => 'node',
00020   );
00021   return $args;
00022 }


Generated on Thu Jul 29 05:00:15 2010 for Panels 2 by  doxygen 1.5.6