vid.inc

Go to the documentation of this file.
00001 <?php
00002 // $Id: vid.inc,v 1.1.2.3 2008/06/03 13:18:07 pancho Exp $
00003 
00004 
00005 /**
00006  * @file arguments/vid.inc
00007  *
00008  * Plugin to provide an argument handler for a vocabulary id
00009  */
00010 function panels_vid_panels_arguments() {
00011   $args['vid'] = array(
00012     'title' => t("Vocabulary ID"),
00013     // keyword to use for %substitution
00014     'keyword' => 'vocabulary',
00015     'description' => t('Loads a vocabulary object from the argument.'),
00016     'context' => 'panels_vid_context',
00017     'settings form' => 'panels_vid_settings_form',
00018     'settings form submit' => 'panels_vid_settings_form_submit',
00019     'displays' => 'panels_vid_displays',
00020     'choose display' => 'panels_vid_choose_display',
00021   );
00022   return $args;
00023 }
00024 
00025 /**
00026  * Discover if this argument gives us the vocabulary we crave.
00027  */
00028 function panels_vid_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('vocabulary');
00032   }
00033 
00034   if (!is_numeric($arg)) {
00035     return FALSE;
00036   }
00037 
00038   $vocabulary = taxonomy_get_vocabulary($arg);
00039   if (!$vocabulary) {
00040     return FALSE;
00041   }
00042 
00043   return panels_context_create('vocabulary', $vocabulary);
00044 }
00045 
00046 /**
00047  * Settings form for the argument
00048  */
00049 function panels_vid_settings_form($conf) {
00050   $options = array();
00051   foreach (taxonomy_get_vocabularies() as $vid => $voc) {
00052     $options[$vid] = $voc->name;
00053   }
00054 
00055   $form['displays'] = array(
00056     '#title' => t('Own display'),
00057     '#type' => 'checkboxes',
00058     '#options' => $options,
00059     '#default_value' => $conf['displays'],
00060     '#description' => t('Each checked vocabulary will get its own special display to layout its content.'),
00061     '#prefix' => '<div class="clear-block">',
00062     '#suffix' => '</div>',
00063   );
00064 
00065   return $form;
00066 }
00067 
00068 /**
00069  * There appears to be a bit of a bug with the way we're handling forms; it causes
00070  * 'checkboxes' to get invalid values added to them when empty. This takes care
00071  * of that.
00072  */
00073 function panels_vid_settings_form_submit(&$values) {
00074   $vocs = taxonomy_get_vocabularies();
00075   if (!empty($values['displays'])) {
00076     foreach ($values['displays'] as $vid => $value) {
00077       if (empty($vocs[$vid])) {
00078         unset($values['displays'][$vid]);
00079       }
00080     }
00081   }
00082 }
00083 
00084 /**
00085  * What additional displays does this argument provide?
00086  */
00087 function panels_vid_displays($conf, $id) {
00088   $displays = array();
00089 
00090   if (is_array($conf['displays'])) {
00091     $options = array();
00092     foreach (taxonomy_get_vocabularies() as $vid => $info) {
00093       $options[$vid] = $info->name;
00094     }
00095     foreach (array_keys(array_filter($conf['displays'])) as $vid) {
00096       $displays[$vid] = array(
00097         'title' => t('vocabulary ID @id @type', array('@id' => $id, '@type' => $options[$vid])),
00098         // Tell it to base the template for this display off of the default.
00099         'default' => 'default',
00100         'context' => 'vocabulary',
00101       );
00102     }
00103   }
00104 
00105   return $displays;
00106 }
00107 
00108 /**
00109  * Based upon the settings and the context, choose which display to use.
00110  */
00111 function panels_vid_choose_display($conf, $context) {
00112   if (empty($context->data)) {
00113     return;
00114   }
00115 
00116   if (!empty($conf['displays'][$context->data->vid])) {
00117     return $context->data->vid;
00118   }
00119 
00120   // Empty return says to use the default display.
00121   return;
00122 }
00123 

Generated on Sun Feb 5 05:00:12 2012 for Panels 2 by  doxygen 1.5.6