function cacheflush_advanced_tab_validation in CacheFlush 8
Same name and namespace in other branches
- 7.3 modules/cacheflush_advanced/cacheflush_advanced.module \cacheflush_advanced_tab_validation()
Implements advanced preset validation.
1 string reference to 'cacheflush_advanced_tab_validation'
- cacheflush_advanced_cacheflush_ui_tabs in modules/
cacheflush_advanced/ cacheflush_advanced.module - Implements hook_cacheflush_ui_tabs().
File
- modules/
cacheflush_advanced/ cacheflush_advanced.module, line 176 - Cacheflush Advanced module.
Code
function cacheflush_advanced_tab_validation($tab, $form, $form_state) {
$element = $form_state
->getTriggeringElement();
if (isset($element['#name']) && ($element['#name'] == 'advance_add' || strpos($element['#name'], 'advanced_remove_') === 0)) {
$form_state
->clearErrors();
}
else {
$storage = $form_state
->getStorage();
$table_elements = $form_state
->getValues()['vertical_tabs_advance']['cacheflush_advanced_table'];
if ($table_elements) {
$container = \Drupal::getContainer();
$bins = array_flip($container
->getParameter('cache_bins'));
foreach ($table_elements as $key => $value) {
if (!empty($value['cid']) && $value['table'] == '0') {
$form_state
->setError($form['vertical_tabs_advance']['cacheflush_advanced_table'][$key]['table'], 'Service is required!');
}
elseif (empty($value['cid']) && $value['table'] != '0') {
$form_state
->setError($form['vertical_tabs_advance']['cacheflush_advanced_table'][$key]['cid'], 'Cache ID is required!');
}
elseif (!empty($value['cid'])) {
$storage['presets']['advanced']['functions'][$key] = [
'#name' => '\\Drupal\\cacheflush\\Controller\\CacheflushApi::clearBinCache',
'#params' => [
$bins[$value['table']],
'delete',
$value['cid'],
],
];
}
}
}
$form_state
->setStorage($storage);
}
}