function Block::blockSubmit
Same name in other branches
- 8.x-3.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 283
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.
unset($configuration['filter']);
if (!empty($allow_settings['disable_filters'])) {
if ($filters = $form_state->getValue([
'override',
'filters',
])) {
foreach ($filters as $filter_name => $filter) {
/** @var \Drupal\views\Plugin\views\filter\FilterPluginBase $plugin */
$plugin = $form_state->getValue([
'override',
'filters',
$filter_name,
'plugin',
]);
$configuration["filter"][$filter_name]['type'] = $plugin->getPluginId();
// Check if we want to disable this filter.
if (!empty($allow_settings['disable_filters'])) {
$disable = $form_state->getValue([
'override',
'filters',
$filter_name,
'disable',
]);
// If marked disabled, we don't really care about other stuff.
if ($disable) {
$configuration["filter"][$filter_name]['disable'] = $disable;
continue;
}
}
}
}
}
// 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);
}