| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @file 4 * 5 * Provides the basic object definitions used by plugins and handlers. 6 */ 7 8 /** 9 * Basic definition for many views objects 10 */ 11 class views_object { 12 /** 13 * Except for displays, options for the object will be held here. 14 */ 15 var $options = array(); 16 /** 17 * Information about options for all kinds of purposes will be held here. 18 * @code 19 * 'option_name' => array( 20 * - 'default' => default value, 21 * - 'translatable' => TRUE/FALSE (wrap in t() on export if true), 22 * - 'contains' => array of items this contains, with its own defaults, etc. 23 * If contains is set, the default will be ignored and assumed to 24 * be array() 25 * 26 * ), 27 * @endcode 28 * Each option may have any of the following functions: 29 * - export_option_OPTIONNAME -- Special export handling if necessary. 30 * - translate_option_OPTIONNAME -- Special handling for translating data 31 * within the option, if necessary. 32 */ 33 function option_definition() { return array(); } 34 35 /** 36 * Views handlers use a special construct function so that we can more 37 * easily construct them with variable arguments. 38 */ 39 function construct() { $this->set_default_options(); } 40 41 /** 42 * Set default options on this object. Called by the constructor in a 43 * complex chain to deal with backward compatibility. 44 */ 45 function options() { } 46 47 /** 48 * Set default options. 49 * For backward compatibility, it sends the options array; this is a 50 * feature that will likely disappear at some point. 51 */ 52 function set_default_options() { 53 $this->_set_option_defaults($this->options, $this->option_definition()); 54 55 // Retained for complex defaults plus backward compatibility. 56 $this->options($this->options); 57 } 58 59 function _set_option_defaults(&$storage, $options, $level = 0) { 60 foreach ($options as $option => $definition) { 61 if (isset($definition['contains']) && is_array($definition['contains'])) { 62 $storage[$option] = array(); 63 $this->_set_option_defaults($storage[$option], $definition['contains'], $level++); 64 } 65 elseif (!empty($definition['translatable']) && !empty($definition['default'])) { 66 $storage[$option] = t($definition['default']); 67 } 68 else { 69 $storage[$option] = isset($definition['default']) ? $definition['default'] : NULL; 70 } 71 } 72 } 73 74 /** 75 * Unpack options over our existing defaults, drilling down into arrays 76 * so that defaults don't get totally blown away. 77 */ 78 function unpack_options(&$storage, $options, $definition = NULL, $check = TRUE) { 79 if ($check && !is_array($options)) { 80 return; 81 } 82 83 if (!isset($definition)) { 84 $definition = $this->option_definition(); 85 } 86 87 foreach ($options as $key => $value) { 88 if (is_array($value)) { 89 if (!isset($storage[$key]) || !is_array($storage[$key])) { 90 $storage[$key] = array(); 91 } 92 93 $this->unpack_options($storage[$key], $value, isset($definition[$key]['contains']) ? $definition[$key]['contains'] : array(), FALSE); 94 } 95 else if (!empty($definition[$key]['translatable']) && !empty($value)) { 96 $storage[$key] = t($value); 97 } 98 else { 99 $storage[$key] = $value; 100 } 101 } 102 } 103 104 /** 105 * Let the handler know what its full definition is. 106 */ 107 function set_definition($definition) { 108 $this->definition = $definition; 109 if (isset($definition['field'])) { 110 $this->real_field = $definition['field']; 111 } 112 } 113 114 function destroy() { 115 if (isset($this->view)) { 116 unset($this->view); 117 } 118 119 if (isset($this->display)) { 120 unset($this->display); 121 } 122 123 if (isset($this->query)) { 124 unset($this->query); 125 } 126 } 127 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Jul 9 18:01:44 2012 | Cross-referenced by PHPXref 0.7 |