function views_object::unpack_translatable

Unpack a single option definition.

This function run's through all suboptions recursive.

Parameters

array $translatable: Stores all available translatable items.

array $storage:

string $option:

string $definition:

array $parents:

array $keys:

1 call to views_object::unpack_translatable()
views_object::unpack_translatables in includes/base.inc
Unpacks each handler to store translatable texts.

File

includes/base.inc, line 342

Class

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

Code

public function unpack_translatable(&$translatable, $storage, $option, $definition, $parents, $keys = array()) {
    // Do not export options for which we have no settings.
    if (!isset($storage[$option])) {
        return;
    }
    // Special handling for some items.
    if (isset($definition['unpack_translatable']) && method_exists($this, $definition['unpack_translatable'])) {
        return $this->{$definition['unpack_translatable']}($translatable, $storage, $option, $definition, $parents, $keys);
    }
    if (isset($definition['translatable'])) {
        if ($definition['translatable'] === FALSE) {
            return;
        }
    }
    // Add the current option to the parents tree.
    $parents[] = $option;
    // If it has child items, unpack those separately.
    if (isset($definition['contains'])) {
        foreach ($definition['contains'] as $sub_option => $sub_definition) {
            $translation_keys = array_merge($keys, array(
                $sub_option,
            ));
            $this->unpack_translatable($translatable, $storage[$option], $sub_option, $sub_definition, $parents, $translation_keys);
        }
    }
    // @todo Figure out this double definition stuff.
    $options = $storage[$option];
    if (is_array($options)) {
        foreach ($options as $key => $value) {
            $translation_keys = array_merge($keys, array(
                $key,
            ));
            if (is_array($value)) {
                $this->unpack_translatable($translatable, $options, $key, $definition, $parents, $translation_keys);
            }
            elseif (!empty($definition[$key]['translatable']) && !empty($value)) {
                // Build source data and add to the array.
                $format = NULL;
                if (isset($definition['format_key']) && isset($options[$definition['format_key']])) {
                    $format = $options[$definition['format_key']];
                }
                $translatable[] = array(
                    'value' => $value,
                    'keys' => $translation_keys,
                    'format' => $format,
                );
            }
        }
    }
    elseif (!empty($definition['translatable']) && !empty($options)) {
        $value = $options;
        // Build source data and add to the array.
        $format = NULL;
        if (isset($definition['format_key']) && isset($storage[$definition['format_key']])) {
            $format = $storage[$definition['format_key']];
        }
        $translatable[] = array(
            'value' => $value,
            'keys' => isset($translation_keys) ? $translation_keys : $parents,
            'format' => $format,
        );
    }
}