function views_object::unpack_options
3.x base.inc | views_object::unpack_options(&$storage, $options, $definition = NULL, |
2.x base.inc | views_object::unpack_options(&$storage, $options, $definition = NULL, $check = TRUE) |
Unpack options over our existing defaults, drilling down into arrays so that defaults don't get totally blown away.
11 calls to views_object::unpack_options()
- views_handler::init in includes/
handlers.inc - init the handler with necessary data.
- views_plugin_access::init in plugins/
views_plugin_access.inc - Initialize the plugin.
- views_plugin_argument_default::init in plugins/
views_plugin_argument_default.inc - Initialize this plugin with the view and the argument it is linked to.
- views_plugin_argument_validate::init in plugins/
views_plugin_argument_validate.inc - Initialize this plugin with the view and the argument it is linked to.
- views_plugin_cache::init in plugins/
views_plugin_cache.inc - Initialize the plugin.
File
- includes/
base.inc, line 102 - Provides the basic object definitions used by plugins and handlers.
Class
- views_object
- Basic definition for many views objects.
Code
function unpack_options(&$storage, $options, $definition = NULL, $all = TRUE, $check = TRUE, $localization_keys = array()) {
if ($check && !is_array($options)) {
return;
}
if (!isset($definition)) {
$definition = $this->option_definition();
}
if (!empty($this->view)) {
// Ensure we have a localization plugin.
$this->view->init_localization();
// Set up default localization keys. Handlers and such set this for us
if (empty($localization_keys) && isset($this->localization_keys)) {
$localization_keys = $this->localization_keys;
}
// but plugins don't because there isn't a common init() these days.
else if (!empty($this->is_plugin)) {
if ($this->plugin_type != 'display') {
$localization_keys = array($this->view->current_display);
$localization_keys[] = $this->plugin_type;
}
}
}
foreach ($options as $key => $value) {
if (is_array($value)) {
// Ignore arrays with no definition.
if (!$all && empty($definition[$key])) {
continue;
}
if (!isset($storage[$key]) || !is_array($storage[$key])) {
$storage[$key] = array();
}
// If we're just unpacking our known options, and we're dropping an
// unknown array (as might happen for a dependent plugin fields) go
// ahead and drop that in.
if (!$all && isset($definition[$key]) && !isset($definition[$key]['contains'])) {
$storage[$key] = $value;
continue;
}
$this->unpack_options($storage[$key], $value, isset($definition[$key]['contains']) ? $definition[$key]['contains'] : array(), $all, FALSE, array_merge($localization_keys, array($key)));
}
// Don't localize strings during editing. When editing, we need to work with
// the original data, not the translated version.
else if (empty($this->view->editing) && !empty($definition[$key]['translatable']) && !empty($value) || !empty($definition['contains'][$key]['translatable']) && !empty($value)) {
if (!empty($this->view) && $this->view->is_translatable()) {
// Allow other modules to make changes to the string before it's
// sent for translation.
// The $keys array is built from the view name, any localization keys
// sent in, and the name of the property being processed.
$format = NULL;
if (isset($definition[$key]['format_key']) && isset($options[$definition[$key]['format_key']])) {
$format = $options[$definition[$key]['format_key']];
}
$translation_data = array(
'value' => $value,
'format' => $format,
'keys' => array_merge(array($this->view->name), $localization_keys, array($key)),
);
$storage[$key] = $this->view->localization_plugin->translate($translation_data);
}
// Otherwise, this is a code-based string, so we can use t().
else {
$storage[$key] = t($value);
}
}
else if ($all || !empty($definition[$key])) {
$storage[$key] = $value;
}
}
}