class ComplexDataConstraint

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/ComplexDataConstraint.php \Drupal\Core\Validation\Plugin\Validation\Constraint\ComplexDataConstraint
  2. 8.9.x core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/ComplexDataConstraint.php \Drupal\Core\Validation\Plugin\Validation\Constraint\ComplexDataConstraint
  3. 11.x core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/ComplexDataConstraint.php \Drupal\Core\Validation\Plugin\Validation\Constraint\ComplexDataConstraint

Complex data constraint.

Validates properties of complex data structures.

Attributes

#[Constraint(id: 'ComplexData', label: new TranslatableMarkup('Complex data', [], [ 'context' => 'Validation', ]))]

Hierarchy

  • class \Drupal\Core\Validation\Plugin\Validation\Constraint\ComplexDataConstraint implements \Symfony\Component\Validator\Constraint

Expanded class hierarchy of ComplexDataConstraint

File

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

Namespace

Drupal\Core\Validation\Plugin\Validation\Constraint
View source
class ComplexDataConstraint extends SymfonyConstraint {
  
  /**
   * An array of constraints for contained properties, keyed by property name.
   *
   * @var array
   */
  public $properties;
  
  /**
   * {@inheritdoc}
   */
  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);
        }
      }
    }
  }
  
  /**
   * {@inheritdoc}
   *
   * @return ?string
   *   Name of the default option.
   *
   * @todo Add method return type declaration.
   * @see https://www.drupal.org/project/drupal/issues/3425150
   */
  public function getDefaultOption() {
    return 'properties';
  }
  
  /**
   * {@inheritdoc}
   *
   * @return array
   *   The names of the required options.
   *
   * @todo Add method return type declaration.
   * @see https://www.drupal.org/project/drupal/issues/3425150
   */
  public function getRequiredOptions() {
    return [
      'properties',
    ];
  }

}

Members

Title Sort descending Modifiers Object type Summary
ComplexDataConstraint::$properties public property An array of constraints for contained properties, keyed by property name.
ComplexDataConstraint::getDefaultOption public function @todo Add method return type declaration.
ComplexDataConstraint::getRequiredOptions public function @todo Add method return type declaration.
ComplexDataConstraint::__construct public function

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