diff --git a/core/lib/Drupal/Core/Installer/Form/SiteConfigureForm.php b/core/lib/Drupal/Core/Installer/Form/SiteConfigureForm.php index 750e967..b616960 100644 --- a/core/lib/Drupal/Core/Installer/Form/SiteConfigureForm.php +++ b/core/lib/Drupal/Core/Installer/Form/SiteConfigureForm.php @@ -239,9 +239,11 @@ public function buildForm(array $form, FormStateInterface $form_state) { * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { - if ($error = user_validate_name($form_state->getValue(array('account', 'name')))) { - $form_state->setErrorByName('account][name', $error); - } + // HELP NEEDED: user_validate_name is broken with the new API, skip it until + // we can work out what is going on. +// if ($error = user_validate_name($form_state->getValue(array('account', 'name')))) { +// $form_state->setErrorByName('account][name', $error); +// } } /** diff --git a/core/lib/Drupal/Core/TypedData/TypedDataManager.php b/core/lib/Drupal/Core/TypedData/TypedDataManager.php old mode 100644 new mode 100755 index d42a3d2..143636d --- a/core/lib/Drupal/Core/TypedData/TypedDataManager.php +++ b/core/lib/Drupal/Core/TypedData/TypedDataManager.php @@ -322,7 +322,7 @@ public function getValidator() { $this->validator = Validation::createValidatorBuilder() ->setMetadataFactory(new MetadataFactory()) ->setTranslator(new DrupalTranslator()) - ->setApiVersion(Validation::API_VERSION_2_4) + ->setApiVersion(Validation::API_VERSION_2_5) ->getValidator(); } return $this->validator; diff --git a/core/lib/Drupal/Core/TypedData/Validation/ClassMetadata.php b/core/lib/Drupal/Core/TypedData/Validation/ClassMetadata.php new file mode 100755 index 0000000..e28c838 --- /dev/null +++ b/core/lib/Drupal/Core/TypedData/Validation/ClassMetadata.php @@ -0,0 +1,105 @@ +isEmpty()) { + $typed_data = NULL; + } + $visitor->visit($this, $typed_data, $group, $propertyPath); + $pathPrefix = isset($propertyPath) && $propertyPath !== '' ? $propertyPath . '.' : ''; + + if ($typed_data) { + foreach ($typed_data as $name => $data) { + $metadata = $this->factory->getMetadataFor($data, $name); + $metadata->accept($visitor, $data, $group, $pathPrefix . $name); + } + } + } + + /** + * {@inheritdoc} + */ + public function hasPropertyMetadata($property_name) { + try { + $exists = (bool)$this->getPropertyMetadata($property_name); + } + catch (\LogicException $e) { + $exists = FALSE; + } + return $exists; + } + + /** + * {@inheritdoc} + */ + public function getPropertyMetadata($property_name) { + if ($this->typedData instanceof ListInterface) { + // HELP NEEDED: Should this use $this->factory instead of creating a new instance? + return array(new Metadata($this->typedData, $property_name, new MetadataFactory())); + } + elseif ($this->typedData instanceof ComplexDataInterface) { + return array(new Metadata($this->typedData->get($property_name), $property_name, new MetadataFactory())); + } + else { + throw new \LogicException("There are no known properties."); + } + } + + /** + * {@inheritdoc} + */ + public function getConstrainedProperties() { + if ($this->typedData instanceof ListInterface) { + return range(0, count($this->typedData) - 1); + } + elseif ($this->typedData instanceof ComplexDataInterface) { + return array_keys($this->typedData->getProperties()); + } + else { + throw new \LogicException("There are no known properties."); + } + } + + /** + * {@inheritdoc} + */ + public function getGroupSequence() { + return NULL; + } + + /** + * {@inheritdoc} + */ + public function hasGroupSequence() { + return FALSE; + } + + /** + * {@inheritdoc} + */ + public function isGroupSequenceProvider() { + return FALSE; + } +} diff --git a/core/lib/Drupal/Core/TypedData/Validation/Metadata.php b/core/lib/Drupal/Core/TypedData/Validation/Metadata.php old mode 100644 new mode 100755 index 73bfc8b..acb0724 --- a/core/lib/Drupal/Core/TypedData/Validation/Metadata.php +++ b/core/lib/Drupal/Core/TypedData/Validation/Metadata.php @@ -8,8 +8,10 @@ namespace Drupal\Core\TypedData\Validation; use Drupal\Core\TypedData\TypedDataInterface; +use Symfony\Component\Validator\Mapping\CascadingStrategy; +use Symfony\Component\Validator\Mapping\TraversalStrategy; +use Symfony\Component\Validator\Mapping\PropertyMetadataInterface; use Symfony\Component\Validator\ValidationVisitorInterface; -use Symfony\Component\Validator\PropertyMetadataInterface; /** * Typed data implementation of the validator MetadataInterface. @@ -101,4 +103,32 @@ public function getPropertyValue($container) { public function getTypedData() { return $this->typedData; } + + /** + * {@inheritdoc} + */ + public function getClassName() { + return $this->typedData->getDataDefinition()->getClass(); + } + + /** + * {@inheritdoc} + */ + public function getConstraints() { + return $this->typedData->getConstraints(); + } + + /** + * {@inheritdoc} + */ + public function getCascadingStrategy() { + return CascadingStrategy::NONE; + } + + /** + * {@inheritdoc} + */ + public function getTraversalStrategy() { + return TraversalStrategy::IMPLICIT; + } } diff --git a/core/lib/Drupal/Core/TypedData/Validation/MetadataFactory.php b/core/lib/Drupal/Core/TypedData/Validation/MetadataFactory.php old mode 100644 new mode 100755 index 2858daf..4dbd2dc --- a/core/lib/Drupal/Core/TypedData/Validation/MetadataFactory.php +++ b/core/lib/Drupal/Core/TypedData/Validation/MetadataFactory.php @@ -10,7 +10,7 @@ use Drupal\Core\TypedData\ComplexDataInterface; use Drupal\Core\TypedData\ListInterface; use Drupal\Core\TypedData\TypedDataInterface; -use Symfony\Component\Validator\MetadataFactoryInterface; +use Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface; /** * Typed data implementation of the validator MetadataFactoryInterface. @@ -31,7 +31,7 @@ public function getMetadataFor($typed_data, $name = '') { throw new \InvalidArgumentException('The passed value must be a typed data object.'); } $is_container = $typed_data instanceof ComplexDataInterface || $typed_data instanceof ListInterface; - $class = '\Drupal\Core\TypedData\Validation\\' . ($is_container ? 'PropertyContainerMetadata' : 'Metadata'); + $class = '\Drupal\Core\TypedData\Validation\\' . ($is_container ? 'ClassMetadata' : 'Metadata'); return new $class($typed_data, $name, $this); } diff --git a/core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/ComplexDataConstraintValidator.php b/core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/ComplexDataConstraintValidator.php old mode 100644 new mode 100755 index 31ffc5b..6cc5b27 --- a/core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/ComplexDataConstraintValidator.php +++ b/core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/ComplexDataConstraintValidator.php @@ -38,10 +38,14 @@ public function validate($value, Constraint $constraint) { $property = $property->getValue(); } elseif ($property->isEmpty()) { - // @see \Drupal\Core\TypedData\Validation\PropertyContainerMetadata::accept(); + // @see \Drupal\Core\TypedData\Validation\ClassMetadata::accept(); $property = NULL; } - $this->context->validateValue($property, $constraints, $name, $group); + + $this->context + ->getValidator() + ->inContext($this->context) + ->validate($property, $constraints, $group); } } } diff --git a/core/modules/user/src/Plugin/Validation/Constraint/UserNameConstraintValidator.php b/core/modules/user/src/Plugin/Validation/Constraint/UserNameConstraintValidator.php index 12d4fa3..887f50f 100644 --- a/core/modules/user/src/Plugin/Validation/Constraint/UserNameConstraintValidator.php +++ b/core/modules/user/src/Plugin/Validation/Constraint/UserNameConstraintValidator.php @@ -20,11 +20,17 @@ class UserNameConstraintValidator extends ConstraintValidator { * {@inheritdoc} */ public function validate($items, Constraint $constraint) { - if (!isset($items) || !$items->value) { + // HELP NEEDED: Why has $items changed from an object + // (presumably TypedData\ListInterface) into an array? + if (!isset($items)) { + $this->context->addViolation($constraint->emptyMessage); + return; + } + $name = is_array($items) ? $items[0]['value'] : $items->first()->value; + if (!$name) { $this->context->addViolation($constraint->emptyMessage); return; } - $name = $items->first()->value; if (substr($name, 0, 1) == ' ') { $this->context->addViolation($constraint->spaceBeginMessage); } diff --git a/core/vendor/symfony/validator/Symfony/Component/Validator/Validator/RecursiveContextualValidator.php b/core/vendor/symfony/validator/Symfony/Component/Validator/Validator/RecursiveContextualValidator.php index 2da1887..c1cfbb5 100644 --- a/core/vendor/symfony/validator/Symfony/Component/Validator/Validator/RecursiveContextualValidator.php +++ b/core/vendor/symfony/validator/Symfony/Component/Validator/Validator/RecursiveContextualValidator.php @@ -419,7 +419,8 @@ private function validateEachObjectIn($collection, $propertyPath, array $groups, // Scalar and null values in the collection are ignored // (BC with Symfony < 2.5) - if (is_object($value)) { + // HELP NEEDED: String can't be validated, I think we're recursing one level too far + if (is_object($value) && ($value instanceof \Drupal\Core\TypedData\ComplexDataInterface || $value instanceof \Drupal\Core\TypedData\ListInterface)) { $this->validateObject( $value, $propertyPath.'['.$key.']',