protected function LanguageWithFallback::getReverseLanguageFallbacks in Search API 8
Retrieves all langcodes that fall back to the given entity translation.
Parameters
\Drupal\Core\Entity\ContentEntityInterface $entity: The entity translation.
Return value
string[] The codes of the languages for which the given entity is the fallback.
1 call to LanguageWithFallback::getReverseLanguageFallbacks()
- LanguageWithFallback::addFieldValues in src/
Plugin/ search_api/ processor/ LanguageWithFallback.php - Adds the values of properties defined by this processor to the item.
File
- src/
Plugin/ search_api/ processor/ LanguageWithFallback.php, line 161
Class
- LanguageWithFallback
- Adds the item's language (with fallbacks) to the indexed data.
Namespace
Drupal\search_api\Plugin\search_api\processorCode
protected function getReverseLanguageFallbacks(ContentEntityInterface $entity) {
$entityLangcode = $entity
->language()
->getId();
$reverseFallbackLangcodes = [
$entityLangcode,
];
foreach ($this->languageManager
->getLanguages() as $langcode => $language) {
if ($langcode === $entityLangcode) {
continue;
}
$context = [
// The fallback_to_passed_entity is recognized by language_fallback_fix
// module and does not change anything if that is not installed.
// It allows to have languages without fallback and will hopefully be
// fixed in core this way or another.
// @see https://www.drupal.org/node/2951294#comment-13127796
'fallback_to_passed_entity' => FALSE,
// We use the entity_upcast operation here, as for the entity_view
// operation, content_translation removes fallbacks that the current
// user does not have access, which would lead to indexing dependent of
// user access.
// @see content_translation_language_fallback_candidates_entity_view_alter()
'operation' => 'entity_upcast',
];
$fallback = $this->entityRepository
->getTranslationFromContext($entity, $langcode, $context);
if ($fallback && $fallback
->language()
->getId() === $entityLangcode) {
$reverseFallbackLangcodes[] = $langcode;
}
}
return $reverseFallbackLangcodes;
}