Skip to content

Commit

Permalink
Merge pull request #199 from biglotteryfund/fix-missing-welsh-link
Browse files Browse the repository at this point in the history
Optionally allow expired entries to be included when checking for translations
  • Loading branch information
mattandrews authored Dec 9, 2019
2 parents 38f77f6 + 6837774 commit dfb8f64
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/ContentHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private static function buildTrailImage($imageField)
]) : null;
}

public static function getCommonFields(Entry $entry, $status, $locale, $includeHeroes = true)
public static function getCommonFields(Entry $entry, $status, $locale, $includeHeroes = true, $includeExpiredForTranslations = false)
{
$fields = [
'id' => $entry->id,
Expand All @@ -39,7 +39,7 @@ public static function getCommonFields(Entry $entry, $status, $locale, $includeH
'postDate' => $entry->postDate,
'dateCreated' => $entry->dateCreated,
'dateUpdated' => $entry->dateUpdated,
'availableLanguages' => EntryHelpers::getAvailableLanguages($entry->id, $locale),
'availableLanguages' => EntryHelpers::getAvailableLanguages($entry->id, $locale, $includeExpiredForTranslations),
'openGraph' => self::extractSocialMetaTags($entry),
// @TODO: Is url used anywhere?
'url' => $entry->url,
Expand Down
8 changes: 7 additions & 1 deletion lib/EntryHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,19 @@ public static function translate($locale, $message, $variables = array())
return \Craft::t('site', $message, $variables, $locale);
}

public static function getAvailableLanguages($entryId, $currentLanguage)
public static function getAvailableLanguages($entryId, $currentLanguage, $includeExpiredForTranslations = false)
{
$statuses = ['live'];
$alternateLanguage = $currentLanguage === 'en' ? 'cy' : 'en';

if ($includeExpiredForTranslations) {
$statuses[] = 'expired';
}

$altEntry = Entry::find()
->id($entryId)
->site($alternateLanguage)
->status($statuses)
->one();

$availableLanguages = [$currentLanguage];
Expand Down
2 changes: 1 addition & 1 deletion lib/FundingProgrammes.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private static function buildTrailImage($imageField)
public function transform(Entry $entry)
{
list('entry' => $entry, 'status' => $status) = EntryHelpers::getDraftOrVersionOfEntry($entry);
$commonFields = ContentHelpers::getCommonFields($entry, $status, $this->locale, $includeHeroes = $this->isSingle);
$commonFields = ContentHelpers::getCommonFields($entry, $status, $this->locale, $includeHeroes = $this->isSingle, $includeExpiredForTranslations = true);

if ($entry->type->handle === 'contentPage') {
return ContentHelpers::getFlexibleContentPage($entry, $this->locale);
Expand Down

0 comments on commit dfb8f64

Please sign in to comment.