2
// $Id: base.inc,v 1.2 2008/06/06 19:29:03 merlinofchaos Exp $
6
* Provides the basic object definitions used by plugins and handlers.
10
* Basic definition for many views objects
14
* Except for displays, options for the object will be held here.
16
var $options = array();
18
* Information about options for all kinds of purposes will be held here.
20
* 'option_name' => array(
21
* - 'default' => default value,
22
* - 'translatable' => TRUE/FALSE (wrap in t() on export if true),
23
* - 'contains' => array of items this contains, with its own defaults, etc.
24
* If contains is set, the default will be ignored and assumed to
29
* Each option may have any of the following functions:
30
* - export_option_OPTIONNAME -- Special export handling if necessary.
31
* - translate_option_OPTIONNAME -- Special handling for translating data
32
* within the option, if necessary.
34
function option_definition() { return array(); }
37
* Views handlers use a special construct function so that we can more
38
* easily construct them with variable arguments.
40
function construct() { $this->set_default_options(); }
43
* Set default options on this object. Called by the constructor in a
44
* complex chain to deal with backward compatibility.
46
function options() { }
49
* Set default options.
50
* For backward compatibility, it sends the options array; this is a
51
* feature that will likely disappear at some point.
53
function set_default_options() {
54
$this->_set_option_defaults($this->options, $this->option_definition());
56
// Retained for complex defaults plus backward compatibility.
57
$this->options($this->options);
60
function _set_option_defaults(&$storage, $options, $level = 0) {
61
foreach ($options as $option => $definition) {
62
if (isset($definition['contains']) && is_array($definition['contains'])) {
63
$storage[$option] = array();
64
$this->_set_option_defaults($storage[$option], $definition['contains'], $level++);
66
elseif (!empty($definition['translatable']) && !empty($definition['default'])) {
67
$storage[$option] = t($definition['default']);
70
$storage[$option] = isset($definition['default']) ? $definition['default'] : NULL;
76
* Unpack options over our existing defaults, drilling down into arrays
77
* so that defaults don't get totally blown away.
79
function unpack_options(&$storage, $options, $definition = NULL) {
80
if (!is_array($options)) {
84
if (!isset($definition)) {
85
$definition = $this->option_definition();
88
foreach ($options as $key => $value) {
89
if (is_array($value)) {
90
if (!isset($storage[$key]) || !is_array($storage[$key])) {
91
$storage[$key] = array();
94
$this->unpack_options($storage[$key], $value, isset($definition[$key]) ? $definition[$key] : array());
96
else if (!empty($definition[$key]['translatable']) && !empty($value)) {
97
$storage[$key] = t($value);
100
$storage[$key] = $value;
106
* Let the handler know what its full definition is.
108
function set_definition($definition) {
109
$this->definition = $definition;
110
if (isset($definition['field'])) {
111
$this->real_field = $definition['field'];
116
if (isset($this->view)) {
120
if (isset($this->display)) {
121
unset($this->display);
124
if (isset($this->query)) {