You are here

class MatchFieldValidator in Form API Validation 8.2

Fapi Validation Plugin for Match Field validation.

Plugin annotation


@FapiValidationValidator(
  id = "match_field",
  error_message = "%field value does not match other field."
)

Hierarchy

Expanded class hierarchy of MatchFieldValidator

File

src/Plugin/FapiValidationValidator/MatchFieldValidator.php, line 17

Namespace

Drupal\fapi_validation\Plugin\FapiValidationValidator
View source
class MatchFieldValidator implements FapiValidationValidatorsInterface {

  /**
   * {@inheritdoc}
   *
   * @todo Find a way to set match field for nested element Ex. $form['contact']['city']. Maybe something like 'match_field[contact/field]' ?
   */
  public function validate(Validator $validator, array $element, FormStateInterface $form_state) {
    $params = $validator
      ->getParams();
    $value = $validator
      ->getValue();
    return $form_state
      ->hasValue($params[0]) && $value == $form_state
      ->getValue($params[0]);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MatchFieldValidator::validate public function @todo Find a way to set match field for nested element Ex. $form['contact']['city']. Maybe something like 'match_field[contact/field]' ? Overrides FapiValidationValidatorsInterface::validate