function ip_ban_disabled_blocks_validate in IP Ban 8
Same name and namespace in other branches
- 7 ip_ban.admin.inc \ip_ban_disabled_blocks_validate()
Determine if blocks entered are valid and formatted correctly.
2 string references to 'ip_ban_disabled_blocks_validate'
- IpBanAdmin::buildForm in src/
IpBanAdmin.php - ip_ban_admin in ./
ip_ban.admin.inc - Ip_ban admin form.
File
- ./
ip_ban.admin.inc, line 186 - Administration functions for the IP Ban module.
Code
function ip_ban_disabled_blocks_validate($form, &$form_state) {
$disabled_blocks = Html::escape($form_state['values']['ip_ban_disabled_blocks']);
if (!empty($disabled_blocks)) {
$disabled_block_array = explode(PHP_EOL, $disabled_blocks);
foreach ($disabled_block_array as $disabled_block) {
// First determine if the user entered two strings separated by a space.
$module_and_delta = explode(',', trim($disabled_block));
if (count($module_and_delta) != 2) {
form_set_error('ip_ban_disabled_blocks', t('You have one or more blocks with an incorrect format; you must enter exactly one module name and delta name per line, separated by a comma.'));
}
else {
$module = trim($module_and_delta[0]);
$delta = trim($module_and_delta[1]);
// Second determine if the block entered is a valid block.
$disabled_block = \Drupal::database()
->query('SELECT * FROM {block} WHERE module = :module AND delta = :delta', array(
':module' => $module,
':delta' => $delta,
))
->fetchAll();
if (empty($disabled_block)) {
form_set_error('ip_ban_disabled_blocks', t('You entered at least one invalid module name or delta; see the help text for how to enter the proper module name and delta.'));
}
// Todo: add check for block enabled status for enabled themes. If block
// disabled for all enabled themes (including admin theme), set form
// error.
}
}
}
}