You are here

function taxonomy_machine_name_form_validate in Taxonomy Machine Name 8

Implements hook_form_validate().

1 string reference to 'taxonomy_machine_name_form_validate'
taxonomy_machine_name_form_taxonomy_term_form_alter in ./taxonomy_machine_name.module
Implements hook_form_FORM_ID_alter().

File

./taxonomy_machine_name.module, line 112
This is the Taxonomy Machine Name module.

Code

function taxonomy_machine_name_form_validate($form, FormStateInterface $form_state) {

  // During the deletion there is no 'machine_name' key.
  if ($form_state
    ->hasValue('machine_name')) {

    // Do not allow machine names to conflict with taxonomy path arguments.
    $machine_name = $form_state
      ->getValue('machine_name');
    $disallowed = [
      'add',
      'list',
      'delete',
      'update',
    ];
    if (in_array($machine_name, $disallowed)) {
      $form_state
        ->setError($form['machine_name'], t('The machine-readable name cannot be "add", "update", "delete" or "list".'));
    }
  }
}