1 base.inc views_object::unpack_options(&$storage, $options, $definition = NULL, $all = TRUE, $check = TRUE, $localization_keys = array())

Unpack options over our existing defaults, drilling down into arrays so that defaults don't get totally blown away.

File

core/modules/views/includes/base.inc, line 96
Provides the basic object definitions used by plugins and handlers.

Class

views_object

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.
    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)));
    }
    // Don't localize strings during editing. When editing, we need to work
    // with the original data, not the translated version.
    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);
      }
      // Otherwise, this is a code-based string, so we can use t().
      else {
        $storage[$key] = t($value);
      }
    }
    elseif ($all || !empty($definition[$key])) {
      $storage[$key] = $value;
    }
  }

}