node_edit.inc

Go to the documentation of this file.
00001 <?php
00002 // $Id: node_edit.inc,v 1.1.2.7 2008/06/03 13:18:07 pancho Exp $
00003 
00004 
00005 /**
00006  * @file arguments/nid.inc
00007  *
00008  * Plugin to provide an argument handler for a Node edit form
00009  */
00010 function panels_node_edit_panels_arguments() {
00011   $args['node_edit'] = array(
00012     'title' => t("Node edit form"),
00013     // keyword to use for %substitution
00014     'keyword' => 'node',
00015     'description' => t('Displays the node edit form for a node.'),
00016     'context' => 'panels_node_edit_context',
00017     'settings form' => 'panels_node_edit_settings_form',
00018     'settings form submit' => 'panels_node_edit_settings_form_submit',
00019     'displays' => 'panels_node_edit_displays',
00020     'choose display' => 'panels_node_edit_choose_display',
00021   );
00022   return $args;
00023 }
00024 
00025 /**
00026  * Discover if this argument gives us the node we crave.
00027  */
00028 function panels_node_edit_context($arg = NULL, $conf = NULL, $empty = FALSE) {
00029   // If unset it wants a generic, unfilled context.
00030   if ($empty) {
00031     return panels_context_create_empty('node_edit_form');
00032   }
00033 
00034   if (!is_numeric($arg)) {
00035     return FALSE;
00036   }
00037 
00038   $node = node_load($arg);
00039   if (!$node) {
00040     return FALSE;
00041   }
00042 
00043   if (array_filter($conf['types']) && empty($conf['types'][$node->type])) {
00044     return FALSE;
00045   }
00046 
00047   // This will perform a node_access check, so we don't have to.
00048   return panels_context_create('node_edit_form', $node);
00049 }
00050 
00051 /**
00052  * Settings form for the argument
00053  */
00054 function panels_node_edit_settings_form($conf) {
00055   $options = array();
00056   foreach (node_get_types() as $type => $info) {
00057     $options[$type] = $info->name;
00058   }
00059   $form['types'] = array(
00060     '#title' => t('Node types'),
00061     '#type' => 'checkboxes',
00062     '#options' => $options,
00063     '#description' => t('You can restrict this argument to use the checked node types. Arguments from non-conforming node types will be ignored, and Panels will behave as if no argument were given. Leave all unchecked to impose no restriction.'),
00064     '#default_value' => $conf['types'],
00065     '#prefix' => '<div class="clear-block">',
00066     '#suffix' => '</div>',
00067   );
00068 
00069   $form['own_default'] = array(
00070     '#title' => t('Use different default display'),
00071     '#type' => 'checkbox',
00072     '#description' => t('If checked, when this argument is present it will use its own display rather than the default. Node types not selected in the "Own display" field will use this one.'),
00073     '#default_value' => $conf['own_default'],
00074   );
00075 
00076   $form['displays'] = array(
00077     '#title' => t('Own display'),
00078     '#type' => 'checkboxes',
00079     '#options' => $options,
00080     '#default_value' => $conf['displays'],
00081     '#description' => t('Each checked node type will get its own special display to layout its content. Only node types set above should be set here. Node types not set here will use the default display.'),
00082     '#prefix' => '<div class="clear-block">',
00083     '#suffix' => '</div>',
00084   );
00085 
00086   return $form;
00087 }
00088 
00089 /**
00090  * There appears to be a bit of a bug with the way we're handling forms; it causes
00091  * 'checkboxes' to get invalid values added to them when empty. This takes care
00092  * of that.
00093  */
00094 function panels_node_edit_settings_form_submit(&$values) {
00095   $types = node_get_types();
00096   if (!empty($values['types'])) {
00097     foreach ($values['types'] as $type => $value) {
00098       if (empty($types[$type])) {
00099         unset($values['types'][$type]);
00100       }
00101     }
00102   }
00103   if (!empty($values['displays'])) {
00104     foreach ($values['displays'] as $type => $value) {
00105       if (empty($types[$type])) {
00106         unset($values['displays'][$type]);
00107       }
00108     }
00109   }
00110 }
00111 
00112 /**
00113  * What additional displays does this argument provide?
00114  */
00115 function panels_node_edit_displays($conf, $id) {
00116   $displays = array();
00117   if (!empty($conf['own_default'])) {
00118     $displays['default'] = array(
00119       'title' => t('Node edit form @id Default', array('@id' => $id)),
00120       'context' => 'node',
00121     );
00122   }
00123 
00124   if (is_array($conf['displays'])) {
00125     $options = array();
00126     foreach (node_get_types() as $type => $info) {
00127       $options[$type] = $info->name;
00128     }
00129     foreach (array_keys(array_filter($conf['displays'])) as $type) {
00130       $displays[$type] = array(
00131         'title' => t('Node edit form @id @type', array('@id' => $id, '@type' => $options[$type])),
00132         // Tell it to base the template for this display off of the default.
00133         'default' => 'default',
00134         'context' => 'node',
00135       );
00136     }
00137   }
00138 
00139   return $displays;
00140 }
00141 
00142 /**
00143  * Based upon the settings and the context, choose which display to use.
00144  */
00145 function panels_node_edit_choose_display($conf, $context) {
00146   if (empty($context->form)) {
00147     return;
00148   }
00149 
00150   if (!empty($conf['displays'][$context->node_type])) {
00151     return $context->node_type;
00152   }
00153 
00154   // Please note that 'default' is a special display.
00155   if (!empty($conf['own_default'])) {
00156     return 'default';
00157   }
00158 
00159   // Empty return says to use the default display.
00160   return;
00161 }
00162 

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