Skip to content
Snippets Groups Projects
Verified Commit 57aabd2b authored by Lee Rowlands's avatar Lee Rowlands
Browse files

Issue #2981889 by Nebel54, acbramley, timodwhit, bkosborne, fago,...

Issue #2981889 by Nebel54, acbramley, timodwhit, bkosborne, fago, josephdpurcell, tim.plunkett, eiriksm, Sam152, grantkruger, shaal, gnikolovski: Performance Degradation in Layout Builder and other places likely
parent 1b0c006a
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,7 @@
namespace Drupal\Core\TypedData\Validation;
use Drupal\Core\Entity\Plugin\DataType\EntityAdapter;
use Drupal\Core\TypedData\ComplexDataInterface;
use Drupal\Core\TypedData\ListInterface;
use Drupal\Core\TypedData\TypedDataInterface;
......@@ -136,6 +137,7 @@ protected function validateNode(TypedDataInterface $data, $constraints = NULL, $
// constraint validators, such that they do not have to care about Typed
// Data.
$value = $typed_data_manager->getCanonicalRepresentation($data);
$constraints_given = isset($constraints);
$this->context->setNode($value, $data, $metadata, $property_path);
if (isset($constraints) || !$this->context->isGroupValidated($cache_key, Constraint::DEFAULT_GROUP)) {
......@@ -148,7 +150,10 @@ protected function validateNode(TypedDataInterface $data, $constraints = NULL, $
// If the data is a list or complex data, validate the contained list items
// or properties. However, do not recurse if the data is empty.
if (($data instanceof ListInterface || $data instanceof ComplexDataInterface) && !$data->isEmpty()) {
// Next, we do not recurse if given constraints are validated against an
// entity, since we should determine whether the entity matches the
// constraints and not whether the entity validates.
if (($data instanceof ListInterface || $data instanceof ComplexDataInterface) && !$data->isEmpty() && !($data instanceof EntityAdapter && $constraints_given)) {
foreach ($data as $name => $property) {
$this->validateNode($property);
}
......
<?php
namespace Drupal\KernelTests\Core\TypedData;
use Drupal\Core\Entity\Plugin\DataType\EntityAdapter;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\KernelTests\KernelTestBase;
/**
* @coversDefaultClass \Drupal\Core\TypedData\Validation\RecursiveContextualValidator
* @group Validation
*/
class RecursiveContextualValidatorTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
public static $modules = [
'entity_test',
'user',
];
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
$this->installEntitySchema('user');
$this->installEntitySchema('entity_test');
}
/**
* Tests recursive validation against given constraints against an entity.
*/
public function testRecursiveValidate() {
$entity = EntityTest::create();
$adapter = EntityAdapter::createFromEntity($entity);
// This would trigger the ValidReferenceConstraint due to EntityTest
// defaulting uid to 1, which doesn't exist. Ensure that we don't get a
// violation for that.
$this->assertCount(0, \Drupal::typedDataManager()->getValidator()->validate($adapter, $adapter->getConstraints()));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment