Skip to content

Commit

Permalink
Remove unpublished pages from the translated languages, move into unt…
Browse files Browse the repository at this point in the history
…ranslated list (#1482)

* Remove unpublished pages from the translated languages, move into untranslated list

Refs getgrav/grav-plugin-sitemap#43

* Add missing part

* Add flags to avoid breaking changes
  • Loading branch information
flaviocopes authored May 19, 2017
1 parent f7266ef commit ce32a08
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions system/src/Grav/Common/Page/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,12 @@ protected function processFrontmatter()

/**
* Return an array with the routes of other translated languages
*
* @param bool $onlyPublished only return published translations
*
* @return array the page translated languages
*/
public function translatedLanguages()
public function translatedLanguages($onlyPublished = false)
{
$filename = substr($this->name, 0, -(strlen($this->extension())));
$config = Grav::instance()['config'];
Expand All @@ -192,6 +195,10 @@ public function translatedLanguages()
$route = $aPage->slug();
}

if ($onlyPublished && !$aPage->published()) {
continue;
}

$translatedLanguages[$language] = $route;
}
}
Expand All @@ -201,9 +208,12 @@ public function translatedLanguages()

/**
* Return an array listing untranslated languages available
*
* @param bool $includeUnpublished also list unpublished translations
*
* @return array the page untranslated languages
*/
public function untranslatedLanguages()
public function untranslatedLanguages($includeUnpublished = false)
{
$filename = substr($this->name, 0, -(strlen($this->extension())));
$config = Grav::instance()['config'];
Expand All @@ -212,7 +222,13 @@ public function untranslatedLanguages()

foreach ($languages as $language) {
$path = $this->path . DS . $this->folder . DS . $filename . '.' . $language . '.md';
if (!file_exists($path)) {
if (file_exists($path)) {
$aPage = new Page();
$aPage->init(new \SplFileInfo($path), $language . '.md');
if ($includeUnpublished && !$aPage->published()) {
$untranslatedLanguages[] = $language;
}
} else {
$untranslatedLanguages[] = $language;
}
}
Expand Down

0 comments on commit ce32a08

Please sign in to comment.