function W3S_validation in Block ID 2.0.x
Implement w3 standards validation alter.
1 string reference to 'W3S_validation'
- block_id_form_block_form_alter in ./
block_id.module - Implements hook_form_FORM_ID_alter().
File
- ./
block_id.module, line 61 - Contains block_id.module.
Code
function W3S_validation(&$form, FormStateInterface $form_state) {
// Block ID field value fatch.
$inputs = $form_state
->getUserInput()['third_party_settings']['block_id']['id'];
if (!empty($inputs)) {
// Checking id has not no space and special characters.
if (preg_match('/[^a-zA-Z_\\-0-9]/i', $inputs)) {
$form_state
->setErrorByName('third_party_settings', t('Attribute ID must be unique, must not contain any space characters & must contain at least one character. Underscore (_) can be used.'));
}
// block list those using block id field.
$block_ids = \Drupal::entityQuery('block')
->condition('third_party_settings', '')
->execute();
// Getting ID's already inserted in another block.
foreach ($block_ids as $ids) {
$block = Block::load($ids);
if ($block
->getThirdPartySetting('block_id', 'id') == $inputs) {
$form_state
->setErrorByName('third_party_settings', t('Attribute ID must be unique. This ID has added in another block.'));
}
}
}
}