You are here

public function RenameAdminPathsCallbacks::validatePath in Rename Admin Paths 8

Form element validation handler for 'name' in form_test_validate_form().

Parameters

string $element: The field element.

\Drupal\Core\Form\FormStateInterface $form_state: The form state object.

File

src/Form/RenameAdminPathsCallbacks.php, line 20

Class

RenameAdminPathsCallbacks
RenameAdminPathsCallbacks class.

Namespace

Drupal\rename_admin_paths\Form

Code

public function validatePath(&$element, FormStateInterface $form_state) {

  // Force path replacement values to contain only lowercase letters, numbers and underscores.
  if (!empty($element['#value']) && !preg_match('!^[a-z0-9_]+$!i', $element['#value'])) {
    $form_state
      ->setError($element, t('Path replacement value must contain only lowercase letters, numbers and underscores.'));
  }
}