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
Loading
Loading
Loading
Loading
+12 −3
Changes for src/MaxLengthCallbacks.php: 12 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -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;
  }


}