reverted: --- b/core/lib/Drupal/Core/Validation/ConstraintManager.php +++ a/core/lib/Drupal/Core/Validation/ConstraintManager.php @@ -108,12 +108,6 @@ 'class' => '\Symfony\Component\Validator\Constraints\Email', 'type' => array('string'), )); - // @todo Should this be turned into a plugin of ours ? - $this->discovery->setDefinition('Count', array( - 'label' => t('Count'), - 'class' => '\Symfony\Component\Validator\Constraints\Count', - 'type' => array(), - )); } /** diff -u b/core/modules/entity_reference/lib/Drupal/entity_reference/Type/ConfigurableEntityReferenceItem.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Type/ConfigurableEntityReferenceItem.php --- b/core/modules/entity_reference/lib/Drupal/entity_reference/Type/ConfigurableEntityReferenceItem.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Type/ConfigurableEntityReferenceItem.php @@ -99,7 +99,7 @@ * since we cannot extend it. */ public static function schema(Field $field) { - $definition = \Drupal::typedData()->getDefinition('field_type:' . $field->type); + $definition = \Drupal::typedData()->getDefinition('configurable_field_type:' . $field->type); $module = $definition['module']; module_load_install($module); $callback = "{$module}_field_schema"; diff -u b/core/modules/field/field.module b/core/modules/field/field.module --- b/core/modules/field/field.module +++ b/core/modules/field/field.module @@ -235,7 +235,7 @@ function field_data_type_info() { // Expose each "configurable field" type as a data type. We add one single // entry, which will be expanded through plugin derivatives. - $items['field_type'] = array( + $items['configurable_field_type'] = array( 'derivative' => '\Drupal\field\Plugin\DataType\ConfigFieldDataTypeDerivative', ); return $items; @@ -322,7 +322,7 @@ $definition = array( 'label' => t('Field !name', array('!name' => $field->id())), // @todo change the prefix to 'configurable something'. - 'type' => 'field_type:' . $field->type, + 'type' => 'configurable_field_type:' . $field->type, 'list' => TRUE, 'configurable' => TRUE, 'translatable' => !empty($field->translatable), diff -u b/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigFieldItemBase.php b/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigFieldItemBase.php --- b/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigFieldItemBase.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigFieldItemBase.php @@ -9,8 +9,7 @@ use Drupal\Core\Entity\Field\FieldItemBase; use Drupal\Core\TypedData\TypedDataInterface; -use Drupal\field\Plugin\Core\Entity\Field; -use Drupal\field\Field as FieldAPI; +use Drupal\field\Field; /** * Base class for 'configurable field type' plugin implementations. @@ -34,7 +33,7 @@ } else { $entity = $parent->getParent(); - $instances = FieldAPI::fieldInfo()->getBundleInstances($entity->entityType(), $entity->bundle()); + $instances = Field::fieldInfo()->getBundleInstances($entity->entityType(), $entity->bundle()); $this->instance = $instances[$parent->name]; } } diff -u b/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetBase.php b/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetBase.php --- b/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetBase.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetBase.php @@ -377,25 +377,9 @@ $violations_by_delta = array(); foreach ($field_state['constraint_violations'] as $violation) { - // @todo Hackish - how do we make that better ? - if ($violation->getPropertyPath()) { - $property_path = explode('.', $violation->getPropertyPath()); - // @todo See https://drupal.org/node/2012682 - base constraints - // violations come with a propertyPath that doesn't contain the delta. - // For now, assign to delta 0. - if (is_numeric($property_path[0])) { - $delta = array_shift($property_path); - } - else { - $delta = 0; - } - } - else { - // For case like "max number of values"... - // @todo Hackish too... - $property_path = array(key($this->field->getColumns())); - $delta = 0; - } + // Separate violations by delta. + $property_path = explode('.', $violation->getPropertyPath()); + $delta = array_shift($property_path); $violation->arrayPropertyPath = $property_path; $violations_by_delta[$delta][] = $violation; } @@ -411,6 +395,7 @@ $delta_element = $element[$original_delta]; } foreach ($delta_violations as $violation) { + // @todo: Pass $violation->arrayPropertyPath as property path. $error_element = $this->errorElement($delta_element, $violation, $form, $form_state); form_error($error_element, $violation->getMessage()); } diff -u b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php --- b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php @@ -362,7 +362,7 @@ $definitions = $wrapped_entity->getPropertyDefinitions($definition); $this->assertEqual($definitions['name']['type'], 'string_field', $entity_type .': Name field found.'); $this->assertEqual($definitions['user_id']['type'], 'entity_reference_field', $entity_type .': User field found.'); - $this->assertEqual($definitions['field_test_text']['type'], 'field_type:text', $entity_type .': Test-text-field field found.'); + $this->assertEqual($definitions['field_test_text']['type'], 'configurable_field_type:text', $entity_type .': Test-text-field field found.'); // Test introspecting an entity object. // @todo: Add bundles and test bundles as well. @@ -371,7 +371,7 @@ $definitions = $entity->getPropertyDefinitions(); $this->assertEqual($definitions['name']['type'], 'string_field', $entity_type .': Name field found.'); $this->assertEqual($definitions['user_id']['type'], 'entity_reference_field', $entity_type .': User field found.'); - $this->assertEqual($definitions['field_test_text']['type'], 'field_type:text', $entity_type .': Test-text-field field found.'); + $this->assertEqual($definitions['field_test_text']['type'], 'configurable_field_type:text', $entity_type .': Test-text-field field found.'); $name_properties = $entity->name->getPropertyDefinitions(); $this->assertEqual($name_properties['value']['type'], 'string', $entity_type .': String value property of the name found.'); diff -u b/core/modules/system/lib/Drupal/system/Tests/TypedData/TypedDataTest.php b/core/modules/system/lib/Drupal/system/Tests/TypedData/TypedDataTest.php --- b/core/modules/system/lib/Drupal/system/Tests/TypedData/TypedDataTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/TypedData/TypedDataTest.php @@ -7,6 +7,7 @@ namespace Drupal\system\Tests\TypedData; +use Drupal\Component\Utility\String; use Drupal\simpletest\DrupalUnitTestBase; use Drupal\Core\Datetime\DrupalDateTime; use DateInterval; @@ -549,4 +550,18 @@ $violations = $this->typedData->create($definition, 0)->validate(); $this->assertEqual($violations->count(), 0); + + // Test validating a list of a values and make sure property paths starting + // with "0" are created. + $definition = array( + 'type' => 'integer_field', + 'list' => TRUE, + ); + $violations = $this->typedData->create($definition, array(array('value' => 10)))->validate(); + $this->assertEqual($violations->count(), 0); + $violations = $this->typedData->create($definition, array(array('value' => 'string')))->validate(); + $this->assertEqual($violations->count(), 1); + + $this->assertEqual($violations[0]->getInvalidValue(), 'string'); + $this->assertIdentical($violations[0]->getPropertyPath(), '0.value'); } } only in patch2: unchanged: --- a/core/lib/Drupal/Core/TypedData/Validation/PropertyContainerMetadata.php +++ b/core/lib/Drupal/Core/TypedData/Validation/PropertyContainerMetadata.php @@ -28,7 +28,7 @@ public function accept(ValidationVisitorInterface $visitor, $typed_data, $group, $typed_data = NULL; } $visitor->visit($this, $typed_data, $group, $propertyPath); - $pathPrefix = empty($propertyPath) ? '' : $propertyPath . '.'; + $pathPrefix = isset($propertyPath) && $propertyPath !== '' ? $propertyPath . '.' : ''; if ($typed_data) { foreach ($typed_data as $name => $data) { only in patch2: unchanged: --- /dev/null +++ b/core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/CountConstraint.php @@ -0,0 +1,37 @@ +