You are here

public static function LingotekJobId::validateJobId in Lingotek Translation 3.7.x

Same name and namespace in other branches
  1. 8.2 src/Element/LingotekJobId.php \Drupal\lingotek\Element\LingotekJobId::validateJobId()
  2. 4.0.x src/Element/LingotekJobId.php \Drupal\lingotek\Element\LingotekJobId::validateJobId()
  3. 3.0.x src/Element/LingotekJobId.php \Drupal\lingotek\Element\LingotekJobId::validateJobId()
  4. 3.1.x src/Element/LingotekJobId.php \Drupal\lingotek\Element\LingotekJobId::validateJobId()
  5. 3.2.x src/Element/LingotekJobId.php \Drupal\lingotek\Element\LingotekJobId::validateJobId()
  6. 3.3.x src/Element/LingotekJobId.php \Drupal\lingotek\Element\LingotekJobId::validateJobId()
  7. 3.4.x src/Element/LingotekJobId.php \Drupal\lingotek\Element\LingotekJobId::validateJobId()
  8. 3.5.x src/Element/LingotekJobId.php \Drupal\lingotek\Element\LingotekJobId::validateJobId()
  9. 3.6.x src/Element/LingotekJobId.php \Drupal\lingotek\Element\LingotekJobId::validateJobId()
  10. 3.8.x src/Element/LingotekJobId.php \Drupal\lingotek\Element\LingotekJobId::validateJobId()

Form element validation handler for job_id elements.

This checks that the submitted value:

  • Does not contain disallowed characters.

File

src/Element/LingotekJobId.php, line 143

Class

LingotekJobId
Provides a job id render element.

Namespace

Drupal\lingotek\Element

Code

public static function validateJobId(&$element, FormStateInterface $form_state, &$complete_form) {

  // Verify that the job ID contains no disallowed characters.
  if (preg_match('@' . $element['#job_id']['replace_pattern'] . '@', $element['#value'])) {
    if (!isset($element['#job_id']['error'])) {
      $form_state
        ->setError($element, t('The job ID name cannot contain invalid chars as "/" or "\\".'));
    }
    else {
      $form_state
        ->setError($element, $element['#job_id']['error']);
    }
  }
}