function ComplexDataConstraint::__construct

Same name in other branches
  1. 9 core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/ComplexDataConstraint.php \Drupal\Core\Validation\Plugin\Validation\Constraint\ComplexDataConstraint::__construct()
  2. 10 core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/ComplexDataConstraint.php \Drupal\Core\Validation\Plugin\Validation\Constraint\ComplexDataConstraint::__construct()
  3. 11.x 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);
            }
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.