summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2018-09-19 18:27:59 (GMT)
committerAlex Pott2018-09-19 18:28:05 (GMT)
commite2ffcb5e03e74780d1c31cb85521cbe021288ecc (patch)
treee01cd5381ea7d5807a8beb310cf66cc3b6bf0092
parent23ae4779afea91121df29d8cd5bee5075c5916da (diff)
Issue #2994398 by tim.plunkett, phenaproxima, vmilic, Berdir, Wim Leers, tedbow, bradjones1: Not properly clearing EntityFieldManager's fieldMap leads to fatals, often after migration or bundle creation
(cherry picked from commit d3784a130005a357ced29ffee4c934e71c43d67d)
-rw-r--r--core/lib/Drupal/Core/Entity/EntityBundleListener.php1
-rw-r--r--core/lib/Drupal/Core/Entity/EntityFieldManager.php2
-rw-r--r--core/modules/language/tests/src/Kernel/Migrate/d6/MigrateLanguageContentSettingsTest.php1
-rw-r--r--core/modules/language/tests/src/Kernel/Migrate/d7/MigrateLanguageContentSettingsTest.php1
-rw-r--r--core/tests/Drupal/KernelTests/Core/Entity/EntityBundleListenerTest.php35
5 files changed, 39 insertions, 1 deletions
diff --git a/core/lib/Drupal/Core/Entity/EntityBundleListener.php b/core/lib/Drupal/Core/Entity/EntityBundleListener.php
index e3b219b..e37317a 100644
--- a/core/lib/Drupal/Core/Entity/EntityBundleListener.php
+++ b/core/lib/Drupal/Core/Entity/EntityBundleListener.php
@@ -68,6 +68,7 @@ class EntityBundleListener implements EntityBundleListenerInterface {
}
// Invoke hook_entity_bundle_create() hook.
$this->moduleHandler->invokeAll('entity_bundle_create', [$entity_type_id, $bundle]);
+ $this->entityFieldManager->clearCachedFieldDefinitions();
}
/**
diff --git a/core/lib/Drupal/Core/Entity/EntityFieldManager.php b/core/lib/Drupal/Core/Entity/EntityFieldManager.php
index f847cfa..88186c6 100644
--- a/core/lib/Drupal/Core/Entity/EntityFieldManager.php
+++ b/core/lib/Drupal/Core/Entity/EntityFieldManager.php
@@ -497,7 +497,7 @@ class EntityFieldManager implements EntityFieldManagerInterface {
}
}
- $this->cacheSet($cid, $this->fieldMap, Cache::PERMANENT, ['entity_types']);
+ $this->cacheSet($cid, $this->fieldMap, Cache::PERMANENT, ['entity_types', 'entity_field_info']);
}
}
return $this->fieldMap;
diff --git a/core/modules/language/tests/src/Kernel/Migrate/d6/MigrateLanguageContentSettingsTest.php b/core/modules/language/tests/src/Kernel/Migrate/d6/MigrateLanguageContentSettingsTest.php
index 546ab25..57439d5 100644
--- a/core/modules/language/tests/src/Kernel/Migrate/d6/MigrateLanguageContentSettingsTest.php
+++ b/core/modules/language/tests/src/Kernel/Migrate/d6/MigrateLanguageContentSettingsTest.php
@@ -25,6 +25,7 @@ class MigrateLanguageContentSettingsTest extends MigrateDrupal6TestBase {
parent::setUp();
$this->installConfig(['node']);
+ $this->installEntitySchema('node');
$this->executeMigrations(['d6_node_type', 'd6_language_content_settings']);
}
diff --git a/core/modules/language/tests/src/Kernel/Migrate/d7/MigrateLanguageContentSettingsTest.php b/core/modules/language/tests/src/Kernel/Migrate/d7/MigrateLanguageContentSettingsTest.php
index e584467..3a07698 100644
--- a/core/modules/language/tests/src/Kernel/Migrate/d7/MigrateLanguageContentSettingsTest.php
+++ b/core/modules/language/tests/src/Kernel/Migrate/d7/MigrateLanguageContentSettingsTest.php
@@ -25,6 +25,7 @@ class MigrateLanguageContentSettingsTest extends MigrateDrupal7TestBase {
parent::setUp();
$this->installConfig(['node']);
+ $this->installEntitySchema('node');
$this->executeMigrations(['d7_node_type', 'd7_language_content_settings']);
}
diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityBundleListenerTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityBundleListenerTest.php
new file mode 100644
index 0000000..c5ace37
--- /dev/null
+++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityBundleListenerTest.php
@@ -0,0 +1,35 @@
+<?php
+
+namespace Drupal\KernelTests\Core\Entity;
+
+/**
+ * @coversDefaultClass \Drupal\Core\Entity\EntityBundleListener
+ *
+ * @group Entity
+ */
+class EntityBundleListenerTest extends EntityKernelTestBase {
+
+ /**
+ * @covers ::onBundleCreate
+ *
+ * Note: Installing the entity_schema_test module will mask the bug this test
+ * was written to cover, as the field map cache is cleared manually by
+ * \Drupal\Core\Field\FieldDefinitionListener::onFieldDefinitionCreate().
+ */
+ public function testOnBundleCreate() {
+ $field_map = $this->container->get('entity_field.manager')->getFieldMap();
+ $expected = [
+ 'entity_test' => 'entity_test',
+ ];
+ $this->assertEquals($expected, $field_map['entity_test']['id']['bundles']);
+
+ entity_test_create_bundle('custom');
+ $field_map = $this->container->get('entity_field.manager')->getFieldMap();
+ $expected = [
+ 'entity_test' => 'entity_test',
+ 'custom' => 'custom',
+ ];
+ $this->assertSame($expected, $field_map['entity_test']['id']['bundles']);
+ }
+
+}