You are here

public function views_object::unpack_options in Views (for Drupal 7) 7.3

Same name and namespace in other branches
  1. 6.3 includes/base.inc \views_object::unpack_options()
  2. 6.2 includes/base.inc \views_object::unpack_options()

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.

... See full list

File

includes/base.inc, line 138
Definition of views_object.

Class

views_object
Provides the basic object definitions used by plugins and handlers.

Code

public 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
      ->altered_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;
    }
    elseif (!empty($this->is_plugin) && empty($localization_keys)) {
      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,
      )));
    }
    elseif (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);
      }
      else {
        $storage[$key] = t($value);
      }
    }
    elseif ($all || !empty($definition[$key])) {
      $storage[$key] = $value;
    }
  }
}