class MaxLengthCallbacks in Maxlength 8
Trusted render callbacks.
Hierarchy
- class \Drupal\maxlength\MaxLengthCallbacks implements TrustedCallbackInterface
Expanded class hierarchy of MaxLengthCallbacks
1 file declares its use of MaxLengthCallbacks
- maxlength.module in ./
maxlength.module - Limits the number of characters in textfields and textareas and shows the amount of characters left.
File
- src/
MaxLengthCallbacks.php, line 11
Namespace
Drupal\maxlengthView source
class MaxLengthCallbacks implements TrustedCallbackInterface {
public static function trustedCallbacks() {
return [
'maxlengthPreRender',
'processElement',
];
}
/**
* Pre render function to set maxlength attributes.
*
* @param array $element
* The render array.
*
* @return array
* The processed render array.
*/
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;
}
/**
* Process handler for the form elements that can have maxlength attribute.
*
* @param array $element
* The render array.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* Form state.
*
* @return array
* The processed render array.
*/
public static function processElement($element, FormStateInterface $form_state) {
if (isset($element['#attributes']['#maxlength_js_enforce']) && $element['#attributes']['#maxlength_js_enforce']) {
$element['#attributes']['class'][] = 'maxlength_js_enforce';
}
if (isset($element['#attributes']['#maxlength_js_truncate_html']) && $element['#attributes']['#maxlength_js_truncate_html']) {
$element['#attributes']['class'][] = 'maxlength_js_truncate_html';
}
return $element;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MaxLengthCallbacks:: |
public static | function | Pre render function to set maxlength attributes. | |
MaxLengthCallbacks:: |
public static | function | Process handler for the form elements that can have maxlength attribute. | |
MaxLengthCallbacks:: |
public static | function |
Lists the trusted callbacks provided by the implementing class. Overrides TrustedCallbackInterface:: |
|
TrustedCallbackInterface:: |
constant | Untrusted callbacks throw exceptions. | ||
TrustedCallbackInterface:: |
constant | Untrusted callbacks trigger silenced E_USER_DEPRECATION errors. | ||
TrustedCallbackInterface:: |
constant | Untrusted callbacks trigger E_USER_WARNING errors. |