| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: features.views.inc,v 1.1.2.26 2010/08/19 16:32:58 yhahn Exp $ 3 4 /** 5 * Implementation of hook_features_export(). 6 */ 7 function views_api_features_export($data, &$export, $module_name = '') { 8 // Add views dependency 9 $export['dependencies']['views'] = 'views'; 10 11 // Add the actual views API hook entries to be accounted for in 12 // hook_views_api(). The components are actually identified by a delimited 13 // list of values: `key:value`. Currently only the 'api' key is supported 14 // as Features does not yet know how to write to subdirectories. 15 foreach ($data as $component) { 16 if (is_numeric($component)) { 17 $version = "api:{$component}"; 18 $export['features']['views_api'][$version] = $version; 19 } 20 } 21 22 return array(); 23 } 24 25 /** 26 * Implementation of hook_features_export_render(). 27 * Adds the views mothership hook, views_api(). 28 */ 29 function views_api_features_export_render($module, $data) { 30 $values = array(); 31 foreach ($data as $component) { 32 $split = explode(':', $component); 33 if (count($split) === 2) { 34 list($key, $value) = $split; 35 $values[$key] = $value; 36 } 37 } 38 $code = ' return ' . features_var_export($values, ' ') . ';'; 39 return array('views_api' => $code); 40 } 41 42 /** 43 * Implementation of hook_features_api(). 44 */ 45 function views_features_api() { 46 return array( 47 'views' => array( 48 'name' => t('Views'), 49 'feature_source' => TRUE, 50 'default_hook' => 'views_default_views', 51 'default_file' => FEATURES_DEFAULTS_CUSTOM, 52 'default_filename' => 'views_default', 53 ), 54 'views_api' => array( 55 'name' => t('Views API'), 56 'feature_source' => FALSE, 57 'duplicates' => FEATURES_DUPLICATES_ALLOWED, 58 // Views API integration does not include a default hook declaration as 59 // it is not a proper default hook. 60 // 'default_hook' => 'views_api', 61 ) 62 ); 63 } 64 65 /** 66 * Implementation of hook_features_export_options(). 67 */ 68 function views_features_export_options() { 69 $enabled_views = array(); 70 $views = views_get_all_views(); 71 foreach ($views as $view) { 72 if (!isset($views[$view->name]->disabled) || !$views[$view->name]->disabled) { 73 $enabled_views[$view->name] = $view->name; 74 } 75 } 76 ksort($enabled_views); 77 return $enabled_views; 78 } 79 80 /** 81 * Implementation of hook_features_export_render(). 82 */ 83 function views_features_export_render($module, $data) { 84 $code = array(); 85 $code[] = ' $views = array();'; 86 $code[] = ''; 87 88 // Build views & add to export array 89 foreach ($data as $view_name) { 90 // Build the view 91 $view = views_get_view($view_name, TRUE); 92 if ($view) { 93 $code[] = ' // Exported view: '. $view_name; 94 $code[] = $view->export(' '); 95 $code[] = ' $views[$view->name] = $view;'; 96 $code[] = ''; 97 } 98 } 99 $code[] = ' return $views;'; 100 $code = implode("\n", $code); 101 return array('views_default_views' => $code); 102 } 103 104 /** 105 * Implementation of hook_features_export(). 106 */ 107 function views_features_export($data, &$export, $module_name = '') { 108 // Build views & add to export array 109 $map = features_get_default_map('views', 'name'); 110 $views = array(); 111 $conflicts = array(); 112 foreach ($data as $view_name) { 113 if ($view = views_get_view($view_name, TRUE)) { 114 // This view is provided by another module. Add it as a dependency or 115 // display a conflict message if the View is overridden. 116 if (isset($map[$view_name]) && $map[$view_name] !== $module_name) { 117 if ($v = views_get_view($view_name)) { 118 if ($v->type === 'Overridden') { 119 $conflicts[$map[$view_name]] = $view_name; 120 } 121 elseif ($v->type === 'Default') { 122 $export['dependencies'][$map[$view_name]] = $map[$view_name]; 123 } 124 } 125 } 126 // Otherwise just add to exports 127 else { 128 $export['features']['views'][$view_name] = $view_name; 129 $views[$view_name] = $view; 130 } 131 } 132 } 133 if (!empty($conflicts)) { 134 $message = 'The following overridden view(s) are provided by other modules: !views. To resolve this problem either revert each view or clone each view so that modified versions can be exported with your feature.'; 135 $tokens = array('!views' => implode(', ', $conflicts)); 136 features_log(t($message, $tokens), 'warning'); 137 } 138 139 // Only add Views API hook if there are actually views to export. 140 if (!empty($export['features']['views'])) { 141 $export['features']['views_api']['api:'. views_api_version()] = 'api:'. views_api_version(); 142 $export['dependencies']['views'] = 'views'; 143 } 144 145 // Discover module dependencies 146 // We need to find dependencies based on: 147 // 1. handlers 148 // 2. plugins (style plugins, display plugins) 149 // 3. other... (e.g. imagecache display option for CCK imagefields) : ( 150 151 // Handlers 152 $handlers = array('fields', 'filters', 'arguments', 'sort', 'relationships'); 153 $handler_dependencies = views_handler_dependencies(); 154 155 // Plugins 156 // For now we only support dependency detection for a subset of all views plugins 157 $plugins = array('display', 'style', 'row', 'access'); 158 $plugin_dependencies = views_plugin_dependencies(); 159 160 foreach ($views as $view) { 161 foreach ($view->display as $display) { 162 // Handlers 163 foreach ($handlers as $handler) { 164 if (isset($display->display_options[$handler])) { 165 foreach ($display->display_options[$handler] as $item) { 166 if ($item['table'] && isset($handler_dependencies[$item['table']])) { 167 $module = $handler_dependencies[$item['table']]; 168 $export['dependencies'][$module] = $module; 169 } 170 } 171 } 172 } 173 174 // Plugins 175 foreach ($plugins as $plugin_type) { 176 $plugin_name = ''; 177 switch ($plugin_type) { 178 case 'display': 179 if (isset($display->display_plugin)) { 180 $plugin_name = $display->display_plugin; 181 } 182 break; 183 case 'access': 184 if (isset($display->display_options['access'], $display->display_options['access']['type']) && $display->display_options['access']['type'] != 'none') { 185 $plugin_name = $display->display_options['access']['type']; 186 } 187 break; 188 default: 189 if (isset($display->display_options["{$plugin_type}_plugin"])) { 190 $plugin_name = $display->display_options["{$plugin_type}_plugin"]; 191 } 192 break; 193 } 194 if (!empty($plugin_name) && isset($plugin_dependencies[$plugin_type][$plugin_name])) { 195 $module = $plugin_dependencies[$plugin_type][$plugin_name]; 196 $export['dependencies'][$module] = $module; 197 } 198 } 199 } 200 } 201 } 202 203 /** 204 * Provides an array that maps hook_views_data() tables to modules. 205 */ 206 function views_handler_dependencies() { 207 views_include_handlers(); 208 209 static $map; 210 if (!isset($map)) { 211 $map = array(); 212 foreach (module_implements('views_data') as $module) { 213 if ($tables = module_invoke($module, 'views_data')) { 214 foreach ($tables as $table => $info) { 215 if (isset($info['table'])) { 216 $map[$table] = $module; 217 } 218 else if (!isset($map[$table])) { 219 $map[$table] = $module; 220 } 221 } 222 } 223 } 224 } 225 return $map; 226 } 227 228 /** 229 * Provides an array that maps hook_views_plugins() to modules. 230 */ 231 function views_plugin_dependencies() { 232 views_include_handlers(); 233 234 static $map; 235 if (!isset($map)) { 236 $map = array(); 237 foreach (module_implements('views_plugins') as $module) { 238 $plugins = module_invoke($module, 'views_plugins'); 239 if (!empty($plugins)) { 240 foreach ($plugins as $type => $items) { 241 if (is_array($items)) { 242 foreach (array_keys($items) as $plugin_name) { 243 $map[$type][$plugin_name] = $module; 244 } 245 } 246 } 247 } 248 } 249 } 250 return $map; 251 } 252 253 /** 254 * Implementation of hook_features_revert(). 255 */ 256 function views_features_revert($module) { 257 if ($default_views = features_get_default('views', $module)) { 258 foreach ($default_views as $default_view) { 259 if ($current_view = views_get_view($default_view->name)) { 260 $current_view->delete(FALSE); 261 } 262 } 263 // Flush caches. 264 cache_clear_all(); 265 menu_rebuild(); 266 } 267 }
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 |