diff --git a/core/modules/config_translation/src/ConfigEntityMapper.php b/core/modules/config_translation/src/ConfigEntityMapper.php index 4a6d275..fd0b353 100644 --- a/core/modules/config_translation/src/ConfigEntityMapper.php +++ b/core/modules/config_translation/src/ConfigEntityMapper.php @@ -117,6 +117,16 @@ public function populateFromRequest(Request $request) { } /** + * Gets the entity instance for this mapper. + * + * @return \Drupal\Core\Config\Entity\ConfigEntityInterface $entity + * The configuration entity. + */ + public function getEntity() { + return $this->entity; + } + + /** * Sets the entity instance for this mapper. * * This method can only be invoked when the concrete entity is known, that is diff --git a/core/modules/config_translation/tests/src/Unit/ConfigEntityMapperTest.php b/core/modules/config_translation/tests/src/Unit/ConfigEntityMapperTest.php index 8041931..443587c 100644 --- a/core/modules/config_translation/tests/src/Unit/ConfigEntityMapperTest.php +++ b/core/modules/config_translation/tests/src/Unit/ConfigEntityMapperTest.php @@ -99,9 +99,9 @@ protected function setUp() { } /** - * Tests ConfigEntityMapper::setEntity(). + * Tests ConfigEntityMapper::setEntity() and ConfigEntityMapper::getEntity(). */ - public function testSetEntity() { + public function testEntityGetterAndSetter() { $this->entity ->expects($this->once()) ->method('id') @@ -119,9 +119,15 @@ public function testSetEntity() { ->with('configurable_language') ->will($this->returnValue($entity_type)); + // No entity is set. + $this->assertNull($this->configEntityMapper->getEntity()); + $result = $this->configEntityMapper->setEntity($this->entity); $this->assertTrue($result); + // Ensure that the getter provides the entity. + $this->assertEquals($this->entity, $this->configEntityMapper->getEntity()); + // Ensure that the configuration name was added to the mapper. $plugin_definition = $this->configEntityMapper->getPluginDefinition(); $this->assertTrue(in_array('config_prefix.entity_id', $plugin_definition['names']));