| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: views_content.module,v 1.4.2.3 2010/08/12 20:35:37 merlinofchaos Exp $ 3 4 /** 5 * @file views_content.module 6 * 7 * Provides views as panels content, configurable by the administrator. 8 * Each view provided as panel content must be configured in advance, 9 * but once configured, building panels with views is a little bit simpler. 10 */ 11 12 /** 13 * Implementation of hook_menu(). 14 */ 15 function views_content_menu() { 16 $items = array(); 17 18 if (!module_exists('panels')) { 19 $items['admin/settings/content-views'] = array( 20 'title' => 'Views panes', 21 'access arguments' => array('administer views content plugin'), 22 'page callback' => 'drupal_get_form', 23 'page arguments' => array('views_content_admin_page'), 24 'description' => 'Configure Views to be used as CTools content.', 25 'type' => MENU_NORMAL_ITEM, 26 ); 27 } 28 29 return $items; 30 } 31 32 /** 33 * Implementation of hook_ctools_plugin_dierctory() to let the system know 34 * where our content_type plugins are. 35 */ 36 function views_content_ctools_plugin_directory($owner, $plugin_type) { 37 if ($owner == 'ctools') { 38 return 'plugins/' . $plugin_type; 39 } 40 } 41 42 /** 43 * Don't show Views' blocks; we expose them already. 44 */ 45 function views_ctools_block_info($module, $delta, &$info) { 46 if (strlen($delta) == 32) { 47 $hashes = variable_get('views_block_hashes', array()); 48 if (!empty($hashes[$delta])) { 49 $delta = $hashes[$delta]; 50 } 51 } 52 53 if (substr($delta, 0, 1) != '-') { 54 $info = NULL; 55 } 56 else { 57 $info['category'] = t('Views'); 58 $info['icon'] = 'icon_views_block_legacy.png'; 59 $info['path'] = drupal_get_path('module', 'views_content'); 60 $info['edit form'] = 'views_content_exposed_form_pane_edit'; 61 $info['add form'] = 'views_content_exposed_form_pane_edit'; 62 $info['render callback'] = 'views_content_exposed_form_pane_render'; 63 } 64 } 65 66 /** 67 * Add settings to the "exposed form in block" views. 68 */ 69 function views_content_exposed_form_pane_edit(&$form, &$form_state) { 70 // This is a cheesy way to add defaults only to new versions of the block 71 // but leave older blocks without the setting alone. We can tell because 72 // all older content will have something set for override_title which is 73 // the only pre-existing setting. 74 if (!isset($form_state['conf']['inherit_path']) && !isset($form_state['conf']['override_title'])) { 75 $form_state['conf']['inherit_path'] = TRUE; 76 } 77 78 $form['inherit_path'] = array( 79 '#type' => 'checkbox', 80 '#title' => t('Inherit path'), 81 '#default_value' => !empty($form_state['conf']['inherit_path']), 82 ); 83 } 84 85 /** 86 * Store data for the exposed form in block settings page. 87 */ 88 function views_content_exposed_form_pane_edit_submit(&$form, &$form_state) { 89 $form_state['conf']['inherit_path'] = $form_state['values']['inherit_path']; 90 } 91 92 /** 93 * Render function for 'special' view blocks. 94 * 95 * We took over the render for the special view blocks so that we could 96 * add options to it. 97 */ 98 function views_content_exposed_form_pane_render($subtype, $conf, $panel_args, $contexts) { 99 $delta = str_replace('views-', '', $subtype); 100 101 if (strlen($delta) == 32) { 102 $hashes = variable_get('views_block_hashes', array()); 103 if (!empty($hashes[$delta])) { 104 $delta = $hashes[$delta]; 105 } 106 } 107 108 list($nothing, $type, $name, $display_id) = explode('-', $delta); 109 // Put the - back on. For views special blocks, the first character is always - but 110 // the explode killed it. Note that this code is mostly copied from views_block(). 111 $type = '-' . $type; 112 if ($view = views_get_view($name)) { 113 if ($view->access($display_id)) { 114 if (!empty($conf['inherit_path'])) { 115 $view->override_path = $_GET['q']; 116 } 117 118 $view->set_display($display_id); 119 if (isset($view->display_handler)) { 120 $block = (object) $view->display_handler->view_special_blocks($type); 121 return $block; 122 } 123 } 124 $view->destroy(); 125 } 126 } 127 128 /** 129 * Implementation of hook_views_api(). 130 * 131 * This one is used as the base to reduce errors when updating. 132 */ 133 function views_content_views_api() { 134 return array( 135 'api' => 2, 136 'path' => drupal_get_path('module', 'views_content') . '/plugins/views', 137 ); 138 } 139 140 /** 141 * Page callback to provide the basic administration form. 142 */ 143 function views_content_admin_page() { 144 $form = array(); 145 views_content_admin_form($form); 146 147 return system_settings_form($form); 148 } 149 150 function views_content_admin_form(&$form) { 151 $form['ctools_content_all_views'] = array( 152 '#type' => 'checkbox', 153 '#title' => t('Make all views available as panes'), 154 '#description' => t("If checked, all views will be made available as content panes to be added to content types. If not checked, only Views that have a 'Content pane' display will be available as content panes. Uncheck this if you want to be able to more carefully control what view content is available to users using the panels layout UI."), 155 '#default_value' => variable_get('ctools_content_all_views', TRUE), 156 ); 157 } 158 159 /** 160 * API function to get the view. 161 */ 162 function views_content_context_get_view(&$context) { 163 if (empty($context->view) || get_class($context->view) == '__PHP_Incomplete_Class') { 164 $context->view = views_get_view($context->data['name']); 165 if ($context->view) { 166 $context->view->set_display($context->data['display']); 167 } 168 } 169 170 return $context->view; 171 } 172 173 /** 174 * API function to get the view. 175 */ 176 function views_content_context_get_output(&$context) { 177 if (empty($context->output)) { 178 $view = views_content_context_get_view($context); 179 $context->output = $view->execute_display($context->data['display']); 180 } 181 182 return $context->output; 183 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Mar 24 11:18:33 2011 | Cross-referenced by PHPXref 0.7 |