public function MefibsDisplayExtender::submitOptionsForm in MEFIBS - More exposed forms in blocks 8
Handle any special handling on the validate form.
Overrides DisplayExtenderPluginBase::submitOptionsForm
File
- lib/
Drupal/ mefibs/ Plugin/ views/ display_extender/ MefibsDisplayExtender.php, line 243 - Contains \Drupal\mefibs\Plugin\views\display_extender\MefibsDisplayExtender.
Class
- MefibsDisplayExtender
- Plugin annotation @ViewsDisplayExtender( id = "mefibs", title = @Translation("Mefibs"), help = @Translation("Provides additional exposed filter blocks for this view."), no_ui = FALSE )
Namespace
Drupal\mefibs\Plugin\views\display_extenderCode
public function submitOptionsForm(&$form, &$form_state) {
if ($form_state['type'] != 'mefibs') {
return;
}
$values = $form_state['values'];
$blocks = $form['mefibs']['#blocks'];
$view = $form_state['view'];
$display_id = $form_state['display_id'];
$display = $view
->getExecutable()->displayHandlers
->get($display_id);
// If the #group property is set on the clicked button, that means we are
// modifying a block, not actually updating the settings.
$button = $form_state['triggering_element'];
if (isset($button['#group'])) {
$action = array_pop($button['#parents']);
array_pop($button['#parents']);
$id = array_pop($button['#parents']);
// Store the action arguments to have them accessible in
// options_form().
$form_state['storage']['action'] = $action;
$form_state['storage']['id'] = $id;
switch ($action) {
case 'add':
// New block to be added.
$blocks[] = array(
'name' => $values['mefibs']['add_block']['name'],
'machine_name' => $values['mefibs']['add_block']['machine_name'],
);
break;
case 'remove':
// Block to be removed.
unset($blocks[$id]);
break;
case 'edit':
// Block to be edited.
break;
case 'save':
// Block to be saved.
$blocks[$id] = array(
'name' => $form_state['input']['mefibs']['blocks'][$id]['name'],
'machine_name' => $form_state['input']['mefibs']['blocks'][$id]['machine_name'],
);
break;
}
$form_state['rerender'] = TRUE;
$form_state['rebuild'] = TRUE;
$view->form_cache = array(
'key' => 'display',
'blocks' => array_values($blocks),
);
}
else {
// Save settings.
$settings = array(
'blocks' => array_values($blocks),
);
$mefibs = $display
->getOption('mefibs');
if ($mefibs) {
$settings = $settings + $mefibs;
}
$display
->setOption('mefibs', $settings);
}
}