vid.inc
Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010 function panels_vid_panels_arguments() {
00011 $args['vid'] = array(
00012 'title' => t("Vocabulary ID"),
00013
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
00027
00028 function panels_vid_context($arg = NULL, $conf = NULL, $empty = FALSE) {
00029
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
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
00070
00071
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
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
00099 'default' => 'default',
00100 'context' => 'vocabulary',
00101 );
00102 }
00103 }
00104
00105 return $displays;
00106 }
00107
00108
00109
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
00121 return;
00122 }
00123