You are here

public function JobItemForm::validateMaxLength in Translation Management Tool 8

Validate that the element is not longer than the max length.

Parameters

array $element: The input element to validate.

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

File

src/Form/JobItemForm.php, line 310

Class

JobItemForm
Form controller for the job item edit forms.

Namespace

Drupal\tmgmt\Form

Code

public function validateMaxLength(array $element, FormStateInterface &$form_state) {
  if (isset($element['#max_length']) && $element['#max_length'] < strlen($element['#value'])) {
    $form_state
      ->setError($element, $this
      ->t('The field has @size characters while the limit is @limit.', [
      '@size' => strlen($element['#value']),
      '@limit' => $element['#max_length'],
    ]));
  }
}