diff --git a/core/lib/Drupal/Core/Entity/EntityInterface.php b/core/lib/Drupal/Core/Entity/EntityInterface.php index 5f84ac9..f02bb1e 100644 --- a/core/lib/Drupal/Core/Entity/EntityInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityInterface.php @@ -91,7 +91,7 @@ public function bundle(); * * @param $langcode * (optional) The language code of the language that should be used for - * getting the label. If set to NULL, the entity's default language is + * getting the label. If set to NULL, the entity's active language is * used. * * @return diff --git a/core/lib/Drupal/Core/Entity/EntityManager.php b/core/lib/Drupal/Core/Entity/EntityManager.php index 46a1ae0..5fc2d16 100644 --- a/core/lib/Drupal/Core/Entity/EntityManager.php +++ b/core/lib/Drupal/Core/Entity/EntityManager.php @@ -10,6 +10,7 @@ use Drupal\Component\Plugin\PluginManagerBase; use Drupal\Component\Plugin\Factory\DefaultFactory; use Drupal\Component\Utility\NestedArray; +use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Language\LanguageManager; use Drupal\Core\Language\Language; @@ -17,8 +18,8 @@ use Drupal\Core\Plugin\Discovery\CacheDecorator; use Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery; use Drupal\Core\Plugin\Discovery\InfoHookDecorator; -use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\StringTranslation\TranslationInterface; +use Drupal\Core\TypedData\TranslatableInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -459,28 +460,30 @@ public function getEntityTypeLabels() { /** * {@inheritdoc} */ - function getTranslationFromContext(ContentEntityInterface $entity, $langcode = NULL, $context = array()) { + public function getTranslationFromContext(EntityInterface $entity, $langcode = NULL, $context = array()) { $translation = $entity; - if (empty($langcode)) { - $langcode = $this->languageManager->getLanguage(Language::TYPE_CONTENT)->id; - } + if ($entity instanceof TranslatableInterface) { + if (empty($langcode)) { + $langcode = $this->languageManager->getLanguage(Language::TYPE_CONTENT)->id; + } - // Retrieve language fallback candidates to perform the entity language - // negotiation. - $context['data'] = $entity; - $context += array('operation' => 'entity_view'); - $candidates = $this->languageManager->getFallbackCandidates($langcode, $context); - - // Ensure the default language has the proper language code. - $default_language = $entity->getUntranslated()->language(); - $candidates[$default_language->id] = Language::LANGCODE_DEFAULT; - - // Return the most fitting entity translation. - foreach ($candidates as $candidate) { - if ($entity->hasTranslation($candidate)) { - $translation = $entity->getTranslation($candidate); - break; + // Retrieve language fallback candidates to perform the entity language + // negotiation. + $context['data'] = $entity; + $context += array('operation' => 'entity_view'); + $candidates = $this->languageManager->getFallbackCandidates($langcode, $context); + + // Ensure the default language has the proper language code. + $default_language = $entity->getUntranslated()->language(); + $candidates[$default_language->id] = Language::LANGCODE_DEFAULT; + + // Return the most fitting entity translation. + foreach ($candidates as $candidate) { + if ($entity->hasTranslation($candidate)) { + $translation = $entity->getTranslation($candidate); + break; + } } } diff --git a/core/lib/Drupal/Core/Entity/EntityManagerInterface.php b/core/lib/Drupal/Core/Entity/EntityManagerInterface.php index 0cfa9be..d561f53 100644 --- a/core/lib/Drupal/Core/Entity/EntityManagerInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityManagerInterface.php @@ -251,7 +251,7 @@ public function getBundleInfo($entity_type); * and if not, it will fall back to the most appropriate translation based on * the provided context. * - * @param \Drupal\Core\Entity\ContentEntityInterface $entity + * @param \Drupal\Core\Entity\EntityInterface $entity * The entity whose translation will be returned. * @param string $langcode * (optional) The language of the current context. Defaults to the current @@ -260,11 +260,11 @@ public function getBundleInfo($entity_type); * (optional) An associative array of arbitrary data that can be useful to * determine the proper fallback sequence. * - * @return \Drupal\Core\Entity\ContentEntityInterface - * A content entity object for the translated data. + * @return \Drupal\Core\Entity\EntityInterface + * An entity object for the translated data. * * @see \Drupal\Core\Language\LanguageManager::getFallbackCandidates() */ - function getTranslationFromContext(ContentEntityInterface $entity, $langcode = NULL, $context = array()); + public function getTranslationFromContext(EntityInterface $entity, $langcode = NULL, $context = array()); }