public function JobItemForm::validateMaxLength

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 312

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'] < mb_strlen($element['#value'])) {
    $form_state
      ->setError($element, $this
      ->t('The field has @size characters while the limit is @limit.', [
      '@size' => mb_strlen($element['#value']),
      '@limit' => $element['#max_length'],
    ]));
  }
}