Skip to content
Snippets Groups Projects
Commit b09eb89f authored by Angie Byron's avatar Angie Byron
Browse files

Issue #1849280 by dawehner: Optimize the performance of PluginBase::setOptionDefaults.

parent dcad36aa
No related branches found
No related tags found
No related merge requests found
......@@ -99,17 +99,29 @@ public function init(ViewExecutable $view, DisplayPluginBase $display, array &$o
*/
protected function defineOptions() { return array(); }
protected function setOptionDefaults(&$storage, $options, $level = 0) {
/**
* Fills up the options of the plugin with defaults.
*
* @param array $storage
* An array which stores the actual option values of the plugin.
* @param array $options
* An array which describes the options of a plugin. Each element is an
* associative array containing:
* - default: The default value of one option
* - (optional) contains: An array which describes the available options
* under the key. If contains is set, the default will be ignored and
* assumed to be an empty array.
* - (optional) 'translatable': TRUE if it should be translated, else FALSE.
* - (optional) 'bool': TRUE if the value is boolean, else FALSE.
*/
protected function setOptionDefaults(array &$storage, array $options) {
foreach ($options as $option => $definition) {
if (isset($definition['contains']) && is_array($definition['contains'])) {
if (isset($definition['contains'])) {
$storage[$option] = array();
$this->setOptionDefaults($storage[$option], $definition['contains'], $level++);
}
elseif (!empty($definition['translatable']) && !empty($definition['default'])) {
$storage[$option] = t($definition['default']);
$this->setOptionDefaults($storage[$option], $definition['contains']);
}
else {
$storage[$option] = isset($definition['default']) ? $definition['default'] : NULL;
$storage[$option] = $definition['default'];
}
}
}
......
......@@ -38,7 +38,7 @@ protected function defineOptions() {
$options['type'] = array('default' => 'yes-no');
$options['type_custom_true'] = array('default' => '', 'translatable' => TRUE);
$options['type_custom_false'] = array('default' => '', 'translatable' => TRUE);
$options['not'] = array('definition bool' => 'reverse');
$options['not'] = array('default' => FALSE, 'bool' => TRUE);
return $options;
}
......
......@@ -37,8 +37,8 @@ protected function defineOptions() {
$options['description_field'] = array('default' => '');
$options['creator_field'] = array('default' => '');
$options['date_field'] = array('default' => '');
$options['guid_field_options']['guid_field'] = array('default' => '');
$options['guid_field_options']['guid_field_is_permalink'] = array('default' => TRUE, 'bool' => TRUE);
$options['guid_field_options']['contains']['guid_field'] = array('default' => '');
$options['guid_field_options']['contains']['guid_field_is_permalink'] = array('default' => TRUE, 'bool' => TRUE);
return $options;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment