function RecursiveContextualValidatorTest::setupTypedData
Same name in other branches
- 9 core/tests/Drupal/Tests/Core/TypedData/RecursiveContextualValidatorTest.php \Drupal\Tests\Core\TypedData\RecursiveContextualValidatorTest::setupTypedData()
- 10 core/tests/Drupal/Tests/Core/TypedData/RecursiveContextualValidatorTest.php \Drupal\Tests\Core\TypedData\RecursiveContextualValidatorTest::setupTypedData()
- 11.x core/tests/Drupal/Tests/Core/TypedData/RecursiveContextualValidatorTest.php \Drupal\Tests\Core\TypedData\RecursiveContextualValidatorTest::setupTypedData()
Setups a typed data object used for test purposes.
Parameters
array $tree: An array of value, constraints and properties.
Return value
\Drupal\Core\TypedData\TypedDataInterface|\PHPUnit\Framework\MockObject\MockObject
2 calls to RecursiveContextualValidatorTest::setupTypedData()
- RecursiveContextualValidatorTest::buildExampleTypedDataWithProperties in core/
tests/ Drupal/ Tests/ Core/ TypedData/ RecursiveContextualValidatorTest.php - Builds some example type data object.
- RecursiveContextualValidatorTest::testValidatePropertyWithCustomGroup in core/
tests/ Drupal/ Tests/ Core/ TypedData/ RecursiveContextualValidatorTest.php - @covers ::validateProperty
File
-
core/
tests/ Drupal/ Tests/ Core/ TypedData/ RecursiveContextualValidatorTest.php, line 194
Class
- RecursiveContextualValidatorTest
- @coversDefaultClass \Drupal\Core\TypedData\Validation\RecursiveContextualValidator @group typedData
Namespace
Drupal\Tests\Core\TypedDataCode
protected function setupTypedData(array $tree, $name = '') {
$callback = function ($value, ExecutionContextInterface $context) {
$context->addViolation('violation: ' . (is_array($value) ? count($value) : $value));
};
$tree += [
'constraints' => [],
];
if (isset($tree['properties'])) {
$map_data_definition = MapDataDefinition::create();
$map_data_definition->addConstraint('Callback', [
'callback' => $callback,
]);
foreach ($tree['properties'] as $property_name => $property) {
$sub_typed_data = $this->setupTypedData($property, $property_name);
$map_data_definition->setPropertyDefinition($property_name, $sub_typed_data->getDataDefinition());
}
$typed_data = $this->typedDataManager
->create($map_data_definition, $tree['value'], $name);
}
else {
/** @var \Drupal\Core\TypedData\TypedDataInterface $typed_data */
$typed_data = $this->typedDataManager
->create(DataDefinition::create('string')->addConstraint('Callback', [
'callback' => $callback,
]), $tree['value'], $name);
}
return $typed_data;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.