function fe_block_machine_name_validate in Features Extra 7
Same name and namespace in other branches
- 6 fe_block.module \fe_block_machine_name_validate()
Validate machine name.
1 string reference to 'fe_block_machine_name_validate'
- fe_block_form_alter in fe_block/
fe_block.module - Implements hook_form_alter().
File
- fe_block/
fe_block.module, line 927 - Provide features components for exporting core blocks and settings.
Code
function fe_block_machine_name_validate($form, &$form_state) {
if (empty($form_state['values']['machine_name'])) {
return;
}
$table = 'fe_block_boxes';
$query = db_select($table)
->condition('bid', $form_state['values']['bid'], '<>')
->condition('machine_name', $form_state['values']['machine_name']);
$count = $query
->countQuery()
->execute()
->fetchField();
if (!preg_match('!^[a-z0-9_]+$!', $form_state['values']['machine_name'])) {
form_set_error('machine_name', t('The machine-readable name must contain only lowercase letters, numbers, and underscores.'));
}
elseif ($count > 0) {
form_set_error('machine_name', t('The machine-readable name has been taken. Please pick another one.'));
}
}