Skip to content
Snippets Groups Projects
Commit 545440d1 authored by Murilo Henrique Pucci's avatar Murilo Henrique Pucci Committed by Clayton Dewey
Browse files

Issue #3195874 by murilohp, scambler, cedewey: Bypass maxlength permission not implemented

parent e3d34c61
No related branches found
No related tags found
No related merge requests found
......@@ -10,6 +10,9 @@ use Drupal\Core\Security\TrustedCallbackInterface;
*/
class MaxLengthCallbacks implements TrustedCallbackInterface {
/**
* {@inheritDoc}
*/
public static function trustedCallbacks() {
return ['maxlengthPreRender', 'processElement'];
}
......@@ -17,13 +20,20 @@ class MaxLengthCallbacks implements TrustedCallbackInterface {
/**
* Pre render function to set maxlength attributes.
*
* @param array $element
* @param array|mixed $element
* The render array.
*
* @return array
* The processed render array.
*/
public static function maxlengthPreRender($element) {
if (\Drupal::currentUser()->hasPermission('bypass maxlength')) {
if (isset($element['#attributes']['maxlength'])) {
$element['#attributes']['maxlength'] = $element['#maxlength'] ?? -1;
}
return $element;
}
if (isset($element['#maxlength_js']) && $element['#maxlength_js'] === TRUE) {
if (((isset($element['#attributes']['maxlength']) && $element['#attributes']['maxlength'] > 0))) {
$element['#attributes']['class'][] = 'maxlength';
......@@ -40,7 +50,7 @@ class MaxLengthCallbacks implements TrustedCallbackInterface {
/**
* Process handler for the form elements that can have maxlength attribute.
*
* @param array $element
* @param array|mixed $element
* The render array.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* Form state.
......@@ -58,5 +68,4 @@ class MaxLengthCallbacks implements TrustedCallbackInterface {
return $element;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment