You are here

public static function MaxLengthCallbacks::maxlengthPreRender in Maxlength 8

Pre render function to set maxlength attributes.

Parameters

array $element: The render array.

Return value

array The processed render array.

File

src/MaxLengthCallbacks.php, line 26

Class

MaxLengthCallbacks
Trusted render callbacks.

Namespace

Drupal\maxlength

Code

public static function maxlengthPreRender($element) {
  if (isset($element['#maxlength_js']) && $element['#maxlength_js'] === TRUE) {
    if (isset($element['#attributes']['maxlength']) && $element['#attributes']['maxlength'] > 0) {
      $element['#attributes']['class'][] = 'maxlength';
      $element['#attached']['library'][] = 'maxlength/maxlength';
    }
    if (isset($element['summary']['#attributes']['maxlength']) && $element['summary']['#attributes']['maxlength'] > 0) {
      $element['summary']['#attributes']['class'][] = 'maxlength';
      $element['summary']['#attached']['library'][] = 'maxlength/maxlength';
    }
  }
  return $element;
}