Unverified Commit e2ffcb5e authored by alexpott's avatar alexpott

Issue #2994398 by tim.plunkett, phenaproxima, vmilic, Berdir, Wim Leers,...

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 d3784a13)
parent 23ae4779
......@@ -68,6 +68,7 @@ public function onBundleCreate($bundle, $entity_type_id) {
}
// Invoke hook_entity_bundle_create() hook.
$this->moduleHandler->invokeAll('entity_bundle_create', [$entity_type_id, $bundle]);
$this->entityFieldManager->clearCachedFieldDefinitions();
}
/**
......
......@@ -497,7 +497,7 @@ public function getFieldMap() {
}
}
$this->cacheSet($cid, $this->fieldMap, Cache::PERMANENT, ['entity_types']);
$this->cacheSet($cid, $this->fieldMap, Cache::PERMANENT, ['entity_types', 'entity_field_info']);
}
}
return $this->fieldMap;
......
......@@ -25,6 +25,7 @@ protected function setUp() {
parent::setUp();
$this->installConfig(['node']);
$this->installEntitySchema('node');
$this->executeMigrations(['d6_node_type', 'd6_language_content_settings']);
}
......
......@@ -25,6 +25,7 @@ protected function setUp() {
parent::setUp();
$this->installConfig(['node']);
$this->installEntitySchema('node');
$this->executeMigrations(['d7_node_type', 'd7_language_content_settings']);
}
......
<?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']);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment