Skip to content

Commit

Permalink
Add internal API method
Browse files Browse the repository at this point in the history
  • Loading branch information
Bozhidar Hristov committed Aug 2, 2017
1 parent 7bbcb6c commit 7b95a4c
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/EventSubscriber/CurrentTranslationLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ public function initializeTranslation(Translatable $entity, $languageOrLocale)
public function getTranslation(Translatable $entity, $languageOrLocale)
{
$translations = $entity->getTranslations();
$translationsFiltered = array_filter(
$translations,

$translation = $translations->filter(
function (Translation $item) use ($languageOrLocale) {
$translationLanguage = $item->getLanguage();
if ($languageOrLocale instanceof Language) {
Expand All @@ -89,12 +89,13 @@ function (Translation $item) use ($languageOrLocale) {
return $translationLanguage->getLocale() === $languageOrLocale;
}
}
);
if (count($translationsFiltered) > 0) {
return reset($translationsFiltered);
)->first();
if ($translation === false) {
return null;

}

return null;
return $translation;
}

public function initializeCurrentTranslation(Translatable $entity)
Expand Down

0 comments on commit 7b95a4c

Please sign in to comment.