You are here

public static function WebformElementHelper::setElementValidate in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Utility/WebformElementHelper.php \Drupal\webform\Utility\WebformElementHelper::setElementValidate()

Set element validate callback.

Parameters

array $element: An element.

array $element_validate: Element validate callback.

Return value

array The element with validate callback.

See also

\Drupal\webform\Plugin\WebformElementBase::hiddenElementAfterBuild

\Drupal\webform\WebformSubmissionConditionsValidator::elementAfterBuild

2 calls to WebformElementHelper::setElementValidate()
WebformElementBase::hiddenElementAfterBuild in src/Plugin/WebformElementBase.php
Webform element #after_build callback.
WebformSubmissionConditionsValidator::elementAfterBuild in src/WebformSubmissionConditionsValidator.php
Webform element #after_build callback: Wrap #element_validate so that we suppress element validation errors.

File

src/Utility/WebformElementHelper.php, line 693

Class

WebformElementHelper
Helper class webform element methods.

Namespace

Drupal\webform\Utility

Code

public static function setElementValidate(array $element, array $element_validate = [
  WebformElementHelper::class,
  'suppressElementValidate',
]) {

  // Element validation can only overridden once so we need to reset
  // the #eleemnt_validate callback.
  if (isset($element['#_element_validate'])) {
    $element['#element_validate'] = $element['#_element_validate'];
    unset($element['#_element_validate']);
  }

  // Wrap #element_validate so that we suppress validation error messages.
  // This only applies visible elements (#access: TRUE) with
  // #element_validate callbacks which are also conditionally hidden.
  if (!empty($element['#element_validate'])) {
    $element['#_element_validate'] = $element['#element_validate'];
    $element['#element_validate'] = [
      $element_validate,
    ];
  }
  return $element;
}