function Block::mapConfigToHandler

Converts form input values to filter handler values.

2 calls to Block::mapConfigToHandler()
Block::blockForm in modules/ctools_views/src/Plugin/Display/Block.php
Adds the configuration form elements specific to this views block plugin.
Block::preBlockBuild in modules/ctools_views/src/Plugin/Display/Block.php
Allows to change the display settings right before executing the block.

File

modules/ctools_views/src/Plugin/Display/Block.php, line 831

Class

Block
Provides a Block display plugin.

Namespace

Drupal\ctools_views\Plugin\Display

Code

protected function mapConfigToHandler(HandlerBase $handler, $input_value) {
    // Convert to the form expected by $handler methods.
    if ($handler->isAGroup()) {
        $identifier = $handler->options['group_info']['identifier'];
        $is_multiple = $handler->multipleExposedInput();
        $value_key = $is_multiple ? 'default_group_multiple' : 'default_group';
        $v = $input_value['group_info'][$value_key] ?? NULL;
        $value = [
            $identifier => $v,
        ];
        $handler->group_info = $value[$identifier];
        $handler->options['group_info'][$value_key] = $handler->group_info;
    }
    else {
        $identifier = $handler->options['expose']['identifier'];
        $use_operator = !empty($handler->options['expose']['use_operator']);
        // The value passed to the handler may need defaults that are not
        // passed with the input values, so we have to attempt to merge the
        // expected values on the plugin before overwriting them.
        if (isset($input_value['value']) && is_array($input_value['value']) && is_array($handler->options['value'])) {
            $value = [
                $identifier => $input_value['value'] + $handler->options['value'],
            ];
        }
        elseif (isset($input_value['value']) && is_string($input_value['value']) && is_array($handler->options['value'])) {
            $value = [
                $identifier => [
                    'value' => $input_value['value'],
                ] + $handler->options['value'],
            ];
        }
        else {
            $value = [
                $identifier => $input_value['value'] ?? NULL,
            ];
        }
        if ($use_operator) {
            $operator_id = $handler->options['expose']['operator_id'];
            $value[$operator_id] = $input_value['operator'];
        }
        $handler->value = $value[$identifier];
        $handler->options['value'] = $handler->value;
        if ($use_operator) {
            $handler->operator = $value[$operator_id];
            $handler->options['operator'] = $handler->operator;
        }
    }
}