function Block::blockSubmit
Same name in other branches
- 4.0.x modules/ctools_views/src/Plugin/Display/Block.php \Drupal\ctools_views\Plugin\Display\Block::blockSubmit()
Overrides Block::blockSubmit
File
-
modules/
ctools_views/ src/ Plugin/ Display/ Block.php, line 453
Class
- Block
- Provides a Block display plugin.
Namespace
Drupal\ctools_views\Plugin\DisplayCode
public function blockSubmit(ViewsBlock $block, $form, FormStateInterface $form_state) {
// Set default value for items_per_page if left blank.
if (empty($form_state->getValue([
'override',
'items_per_page',
]))) {
$form_state->setValue([
'override',
'items_per_page',
], "none");
}
parent::blockSubmit($block, $form, $form_state);
$configuration = $block->getConfiguration();
$allow_settings = array_filter($this->getOption('allow'));
// Save "Pager type" settings to block configuration.
if (!empty($allow_settings['pager'])) {
if ($pager = $form_state->getValue([
'override',
'pager',
])) {
$configuration['pager'] = $pager;
}
}
// Save "Pager offset" settings to block configuration.
if (!empty($allow_settings['offset'])) {
$configuration['pager_offset'] = $form_state->getValue([
'override',
'pager_offset',
]);
}
// Save "Hide fields" / "Reorder fields" settings to block configuration.
if (!empty($allow_settings['hide_fields']) || !empty($allow_settings['sort_fields'])) {
if ($fields = array_filter($form_state->getValue([
'override',
'order_fields',
]))) {
uasort($fields, '\\Drupal\\ctools_views\\Plugin\\Display\\Block::sortFieldsByWeight');
$configuration['fields'] = $fields;
}
}
// Save "Configure filters" / "Disable filters" settings to block
// configuration.
if (!empty($allow_settings['configure_filters'])) {
// Store the validated and raw exposed filters.
$handlers = $this->view
->getDisplay()
->getHandlers('filter');
// Map form values back to views_field type data.
$values = $form_state->getValue('exposed');
foreach ($handlers as $key => $handler) {
if ($handler->canExpose() && $handler->isExposed()) {
$identifier = $handler->options['expose']['identifier'];
$config_key = "filter-{$key}";
if (isset($values[$config_key])) {
// Save values from generated form/values array, which may or may
// not use a wrapper.
$wrapper = !empty($values[$config_key][$identifier . '_wrapper']) ? $identifier . '_wrapper' : FALSE;
if ($wrapper) {
$configuration['exposed'][$config_key] = $this->extractExposedValues($handler, $form['settings']['exposed'][$config_key][$wrapper], $values[$config_key][$wrapper]);
}
else {
$configuration['exposed'][$config_key] = $this->extractExposedValues($handler, $form['settings']['exposed'][$config_key], $values[$config_key]);
}
$configuration['exposed'][$config_key]['plugin_id'] = $handler->getPluginId();
$configuration['exposed'][$config_key]['exposed'] = $values[$config_key]['exposed'];
if ($values[$config_key]['exposed'] && isset($values[$config_key]['use_operator'])) {
$configuration['exposed'][$config_key]['expose']['use_operator'] = $values[$config_key]['use_operator'];
}
else {
$configuration['exposed'][$config_key]['expose']['use_operator'] = FALSE;
}
}
}
}
}
unset($configuration['filter']);
if (!empty($allow_settings['disable_filters'])) {
if ($filters = $form_state->getValue([
'override',
'filters',
])) {
foreach ($filters as $filter_name => $filter) {
$disable = $filter['disable'];
if ($disable) {
$configuration['filter'][$filter_name]['disable'] = $disable;
}
}
}
}
// Save "Configure sorts" settings to block configuration.
if (!empty($allow_settings['configure_sorts'])) {
$sorts = $form_state->getValue([
'override',
'sort',
]);
foreach ($sorts as $sort_name => $sort) {
$plugin = $sort['plugin'];
// Check if we want to override the default sort order.
if ($plugin->options['order'] != $sort['order']) {
$configuration['sort'][$sort_name] = $sort['order'];
}
}
}
$block->setConfiguration($configuration);
}