diff -u b/core/lib/Drupal/Core/Entity/EntityManager.php b/core/lib/Drupal/Core/Entity/EntityManager.php --- b/core/lib/Drupal/Core/Entity/EntityManager.php +++ b/core/lib/Drupal/Core/Entity/EntityManager.php @@ -484,42 +484,6 @@ /** * {@inheritdoc} */ - public function getExtraFields($entity_type_id, $bundle) { - // Read from the "static" cache. - if (isset($this->bundleExtraFields[$entity_type_id][$bundle])) { - return $this->bundleExtraFields[$entity_type_id][$bundle]; - } - - // Read from the persistent cache. Since hook_entity_extra_field_info() and - // hook_entity_extra_field_info_alter() might contain t() calls, we cache - // per language. - $cache_id = 'entity_bundle_extra_fields:' . $entity_type_id . ':' . $bundle . ':' . $this->languageManager->getCurrentLanguage()->id; - $cached = $this->cache->get($cache_id); - if ($cached) { - $this->bundleExtraFields[$entity_type_id][$bundle] = $cached->data; - return $this->bundleExtraFields[$entity_type_id][$bundle]; - } - - $extra = $this->moduleHandler->invokeAll('entity_extra_field_info'); - $this->moduleHandler->alter('entity_extra_field_info', $extra); - $info = isset($extra[$entity_type_id][$bundle]) ? $extra[$entity_type_id][$bundle] : array(); - $info += array( - 'form' => array(), - 'display' => array(), - ); - - // Store in the 'static' and persistent caches. - $this->bundleExtraFields[$entity_type_id][$bundle] = $info; - $this->cache->set($cache_id, $info, Cache::PERMANENT, array( - 'entity_field_info' => TRUE, - )); - - return $this->bundleExtraFields[$entity_type_id][$bundle]; - } - - /** - * {@inheritdoc} - */ public function getEntityTypeLabels() { $options = array(); foreach ($this->getDefinitions() as $entity_type => $definition) { @@ -563,6 +527,42 @@ /** * {@inheritdoc} */ + public function getExtraFields($entity_type_id, $bundle) { + // Read from the "static" cache. + if (isset($this->bundleExtraFields[$entity_type_id][$bundle])) { + return $this->bundleExtraFields[$entity_type_id][$bundle]; + } + + // Read from the persistent cache. Since hook_entity_extra_field_info() and + // hook_entity_extra_field_info_alter() might contain t() calls, we cache + // per language. + $cache_id = 'entity_bundle_extra_fields:' . $entity_type_id . ':' . $bundle . ':' . $this->languageManager->getCurrentLanguage()->id; + $cached = $this->cache->get($cache_id); + if ($cached) { + $this->bundleExtraFields[$entity_type_id][$bundle] = $cached->data; + return $this->bundleExtraFields[$entity_type_id][$bundle]; + } + + $extra = $this->moduleHandler->invokeAll('entity_extra_field_info'); + $this->moduleHandler->alter('entity_extra_field_info', $extra); + $info = isset($extra[$entity_type_id][$bundle]) ? $extra[$entity_type_id][$bundle] : array(); + $info += array( + 'form' => array(), + 'display' => array(), + ); + + // Store in the 'static' and persistent caches. + $this->bundleExtraFields[$entity_type_id][$bundle] = $info; + $this->cache->set($cache_id, $info, Cache::PERMANENT, array( + 'entity_field_info' => TRUE, + )); + + return $this->bundleExtraFields[$entity_type_id][$bundle]; + } + + /** + * {@inheritdoc} + */ public function getEntityTypeLabels() { $options = array(); foreach ($this->getDefinitions() as $entity_type => $definition) { diff -u b/core/modules/system/entity.api.php b/core/modules/system/entity.api.php --- b/core/modules/system/entity.api.php +++ b/core/modules/system/entity.api.php @@ -869,8 +869,8 @@ * @see hook_entity_extra_field_info_alter() * * @return array - * The array structure is identical to that of the return value of - * \Drupal\Core\Entity\EntityManagerInterface::getExtraFields(). + * The array structure is identical to that of the return value of + * \Drupal\Core\Entity\EntityManagerInterface::getExtraFields(). */ function hook_entity_extra_field_info() { $extra = array(); @@ -915,8 +915,8 @@ * Alter "pseudo-field" components on fieldable entities. * * @param array $info - * The array structure is identical to that of the return value of - * \Drupal\Core\Entity\EntityManagerInterface::getExtraFields(). + * The array structure is identical to that of the return value of + * \Drupal\Core\Entity\EntityManagerInterface::getExtraFields(). * * @see hook_entity_extra_field_info() */ interdiff impossible; taking evasive action reverted: --- b/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php +++ a/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php @@ -781,58 +781,6 @@ } /** - * @covers ::getExtraFields - */ - function testgetExtraFields() { - $this->setUpEntityManager(); - - $entity_type_id = $this->randomName(); - $bundle = $this->randomName(); - $language_code = 'en'; - $hook_bundle_extra_fields = array( - $entity_type_id => array( - $bundle => array( - 'form' => array( - 'foo_extra_field' => array( - 'label' => 'Foo', - ), - ), - ), - ), - ); - $processed_hook_bundle_extra_fields = $hook_bundle_extra_fields; - $processed_hook_bundle_extra_fields[$entity_type_id][$bundle] += array( - 'display' => array(), - ); - $cache_id = 'entity_bundle_extra_fields:' . $entity_type_id . ':' . $bundle . ':' . $language_code; - - $language = new Language(); - $language->id = $language_code; - - $this->languageManager->expects($this->once()) - ->method('getCurrentLanguage') - ->will($this->returnValue($language)); - - $this->cache->expects($this->once()) - ->method('get') - ->with($cache_id); - - $this->moduleHandler->expects($this->once()) - ->method('invokeAll') - ->with('entity_extra_field_info') - ->will($this->returnValue($hook_bundle_extra_fields)); - $this->moduleHandler->expects($this->once()) - ->method('alter') - ->with('entity_extra_field_info', $hook_bundle_extra_fields); - - $this->cache->expects($this->once()) - ->method('set') - ->with($cache_id, $processed_hook_bundle_extra_fields[$entity_type_id][$bundle]); - - $this->assertSame($processed_hook_bundle_extra_fields[$entity_type_id][$bundle], $this->entityManager->getExtraFields($entity_type_id, $bundle)); - } - - /** * Gets a mock controller class name. * * @return string unchanged: --- a/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php @@ -817,6 +817,58 @@ public function testGetTranslationFromContext() { } /** + * @covers ::getExtraFields + */ + function testgetExtraFields() { + $this->setUpEntityManager(); + + $entity_type_id = $this->randomName(); + $bundle = $this->randomName(); + $language_code = 'en'; + $hook_bundle_extra_fields = array( + $entity_type_id => array( + $bundle => array( + 'form' => array( + 'foo_extra_field' => array( + 'label' => 'Foo', + ), + ), + ), + ), + ); + $processed_hook_bundle_extra_fields = $hook_bundle_extra_fields; + $processed_hook_bundle_extra_fields[$entity_type_id][$bundle] += array( + 'display' => array(), + ); + $cache_id = 'entity_bundle_extra_fields:' . $entity_type_id . ':' . $bundle . ':' . $language_code; + + $language = new Language(); + $language->id = $language_code; + + $this->languageManager->expects($this->once()) + ->method('getCurrentLanguage') + ->will($this->returnValue($language)); + + $this->cache->expects($this->once()) + ->method('get') + ->with($cache_id); + + $this->moduleHandler->expects($this->once()) + ->method('invokeAll') + ->with('entity_extra_field_info') + ->will($this->returnValue($hook_bundle_extra_fields)); + $this->moduleHandler->expects($this->once()) + ->method('alter') + ->with('entity_extra_field_info', $hook_bundle_extra_fields); + + $this->cache->expects($this->once()) + ->method('set') + ->with($cache_id, $processed_hook_bundle_extra_fields[$entity_type_id][$bundle]); + + $this->assertSame($processed_hook_bundle_extra_fields[$entity_type_id][$bundle], $this->entityManager->getExtraFields($entity_type_id, $bundle)); + } + + /** * Gets a mock controller class name. * * @return string