You are here

public function ComplexDataConstraint::__construct in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/ComplexDataConstraint.php \Drupal\Core\Validation\Plugin\Validation\Constraint\ComplexDataConstraint::__construct()
  2. 9 core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/ComplexDataConstraint.php \Drupal\Core\Validation\Plugin\Validation\Constraint\ComplexDataConstraint::__construct()

File

core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/ComplexDataConstraint.php, line 29

Class

ComplexDataConstraint
Complex data constraint.

Namespace

Drupal\Core\Validation\Plugin\Validation\Constraint

Code

public function __construct($options = NULL) {

  // Allow skipping the 'properties' key in the options.
  if (is_array($options) && !array_key_exists('properties', $options)) {
    $options = [
      'properties' => $options,
    ];
  }
  parent::__construct($options);
  $constraint_manager = \Drupal::service('validation.constraint');

  // Instantiate constraint objects for array definitions.
  foreach ($this->properties as &$constraints) {
    foreach ($constraints as $id => $options) {
      if (!is_object($options)) {
        $constraints[$id] = $constraint_manager
          ->create($id, $options);
      }
    }
  }
}