node_add.inc

Go to the documentation of this file.
00001 <?php
00002 // $Id: node_add.inc,v 1.1.2.9 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 add form
00009  */
00010 function panels_node_add_panels_arguments() {
00011   $args['node_add'] = array(
00012     'title' => t("Node add form"),
00013     // keyword to use for %substitution
00014     'keyword' => 'node_type',
00015     'description' => t('Displays the node add form for a content type.'),
00016     'context' => 'panels_node_add_context',
00017     'settings form' => 'panels_node_add_settings_form',
00018     'settings form submit' => 'panels_node_add_settings_form_submit',
00019     'displays' => 'panels_node_add_displays',
00020     'choose display' => 'panels_node_add_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_add_context($arg = NULL, $conf = NULL, $empty = FALSE) {
00029   // If unset it wants a generic, unfilled context.
00030   if (!isset($arg)) {
00031     return panels_context_create_empty('node_add_form');
00032   }
00033 
00034   if (array_filter($conf['types']) && empty($conf['types'][$arg])) {
00035     return FALSE;
00036   }
00037 
00038   return panels_context_create('node_add_form', $arg);
00039 }
00040 
00041 /**
00042  * Settings form for the argument
00043  */
00044 function panels_node_add_settings_form($conf) {
00045   $options = array();
00046   foreach (node_get_types() as $type => $info) {
00047     $options[$type] = $info->name;
00048   }
00049   $form['types'] = array(
00050     '#title' => t('Node types'),
00051     '#type' => 'checkboxes',
00052     '#options' => $options,
00053     '#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.'),
00054     '#default_value' => $conf['types'],
00055     '#prefix' => '<div class="clear-block">',
00056     '#suffix' => '</div>',
00057   );
00058 
00059   $form['own_default'] = array(
00060     '#title' => t('Use different default display'),
00061     '#type' => 'checkbox',
00062     '#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.'),
00063     '#default_value' => $conf['own_default'],
00064   );
00065 
00066   $form['displays'] = array(
00067     '#title' => t('Own display'),
00068     '#type' => 'checkboxes',
00069     '#options' => $options,
00070     '#default_value' => $conf['displays'],
00071     '#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.'),
00072     '#prefix' => '<div class="clear-block">',
00073     '#suffix' => '</div>',
00074   );
00075 
00076   return $form;
00077 }
00078 
00079 /**
00080  * There appears to be a bit of a bug with the way we're handling forms; it causes
00081  * 'checkboxes' to get invalid values added to them when empty. This takes care
00082  * of that.
00083  */
00084 function panels_node_add_settings_form_submit(&$values) {
00085   $types = node_get_types();
00086   if (!empty($values['types'])) {
00087     foreach ($values['types'] as $type => $value) {
00088       if (empty($types[$type])) {
00089         unset($values['types'][$type]);
00090       }
00091     }
00092   }
00093   if (!empty($values['displays'])) {
00094     foreach ($values['displays'] as $type => $value) {
00095       if (empty($types[$type])) {
00096         unset($values['displays'][$type]);
00097       }
00098     }
00099   }
00100 }
00101 
00102 /**
00103  * Based upon the settings and the context, choose which display to use.
00104  */
00105 function panels_node_add_choose_display($conf, $context) {
00106   if (empty($context->form)) {
00107     return;
00108   }
00109 
00110   if (!empty($conf['displays'][$context->node_type])) {
00111     return $context->node_type;
00112   }
00113 
00114   // Please note that 'default' is a special display.
00115   if (!empty($conf['own_default'])) {
00116     return 'default';
00117   }
00118 
00119   // Empty return says to use the default display.
00120   return;
00121 }
00122 
00123 /**
00124  * What additional displays does this argument provide?
00125  */
00126 function panels_node_add_displays($conf, $id) {
00127   $displays = array();
00128   if (!empty($conf['own_default'])) {
00129     $displays['default'] = array(
00130       'title' => t('Node add form @id Default', array('@id' => $id)),
00131       'context' => 'node',
00132     );
00133   }
00134 
00135   if (is_array($conf['displays'])) {
00136     $options = array();
00137     foreach (node_get_types() as $type => $info) {
00138       $options[$type] = $info->name;
00139     }
00140     foreach (array_keys(array_filter($conf['displays'])) as $type) {
00141       if (!empty($options[$type])) {
00142         $displays[$type] = array(
00143           'title' => t('Node add form @id @type', array('@id' => $id, '@type' => $options[$type])),
00144           // Tell it to base the template for this display off of the default.
00145           'default' => 'default',
00146           'context' => 'node',
00147         );
00148       }
00149     }
00150   }
00151 
00152   return $displays;
00153 }
00154 

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