Problem/Motivation

When a composite contraint is initilized in the ContraintManager it 'strips' any configuration you might have.

I'd like to be able to:

AtLeastOneOf:
      messageCollection: 'Either block_id and block_revision_id, or block_serialized must be provided.'
      constraints:
        - ... etc

But currently that is not possible. Initial testing shows the below code works, which could be adapted to the ConstraintManager.

/**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    $constraint_manager = $container->get('validation.constraint');
    $constraints = $configuration['constraints'];
    $constraint_instances = [];
    foreach ($constraints as $constraint_id => $constraint) {
      foreach ($constraint as $constraint_name => $constraint_options) {
        $constraint_instances[$constraint_id] = $constraint_manager->create($constraint_name, $constraint_options);
      }
    }

    unset($configuration['constraints']);
    return new static($constraint_instances, [SymfonyConstraint::DEFAULT_GROUP], ...$configuration);
  }

Steps to reproduce

Proposed resolution

Ajust the ConstraintManager to allow for options to be passed. Needs proper testing though.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Comments

bbrala created an issue. See original summary.

bbrala’s picture

Issue summary: View changes
bbrala’s picture

Parent is merged, so we can move on with this.

bbrala’s picture

This might be outdated. #3535734: Make block.settings.inline_block:* fully validatable does set collectionMessage on a collection constrant...

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.