diff --git a/core/lib/Drupal/Core/Entity/Query/QueryBase.php b/core/lib/Drupal/Core/Entity/Query/QueryBase.php index 586af6907cea84235d4599173c211f825aad7dbf..9ad26e1e6e4c8232928fdbcd47c48692eb5d83c2 100644 --- a/core/lib/Drupal/Core/Entity/Query/QueryBase.php +++ b/core/lib/Drupal/Core/Entity/Query/QueryBase.php @@ -233,4 +233,10 @@ public function tableSort(&$headers) { return $this; } + /** + * Makes sure that the Condition object is cloned as well. + */ + function __clone() { + $this->condition = clone $this->condition; + } } diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryTest.php index a7afcc60b085425bfc995089655d93f22717d49e..8c04faac22778091af20ec544194c7c2bd1e4ca4 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryTest.php @@ -156,6 +156,20 @@ function testEntityQuery() { // 15) needs to be set. $this->assertResult(1, 3, 4, 5, 6, 7, 9, 11, 12, 13, 14, 15); + // Test cloning of query conditions. + $query = $this->factory->get('test_entity') + ->condition("$figures.color", 'red') + ->sort('ftid'); + $cloned_query = clone $query; + $cloned_query + ->condition("$figures.shape", 'circle'); + // Bit 0 (1, 3, 5, 7, 9, 11, 13, 15) needs to be set. + $this->queryResults = $query->execute(); + $this->assertResult(1, 3, 5, 7, 9, 11, 13, 15); + // No red color has a circle shape. + $this->queryResults = $cloned_query->execute(); + $this->assertResult(); + $query = $this->factory->get('test_entity'); $group = $query->orConditionGroup() ->exists($greetings, 'tr')