Skip to content

Commit

Permalink
get default language if translation doesn't exists in the active lang…
Browse files Browse the repository at this point in the history
…uage
  • Loading branch information
guga-grigolia committed Nov 11, 2017
1 parent 95db39a commit 2acb314
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions models/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* @property string $body
* @property PageTranslation[] $translations
* @property PageTranslation $activeTranslation
* @property PageTranslation $defaultTranslation
*/
class Page extends TranslatableModel
{
Expand Down Expand Up @@ -175,11 +176,22 @@ public static function getById($id)

public function getTitle()
{
return $this->activeTranslation ? $this->activeTranslation->title : '';
return $this->getTranslation() ? $this->getTranslation()->title : '';
}

public function getBody()
{
return $this->activeTranslation ? $this->activeTranslation->getBody() : '';
return $this->getTranslation() ? $this->getTranslation()->getBody() : '';
}
public function getTranslation()
{
return $this->activeTranslation ?: $this->defaultTranslation;
}

public function getDefaultTranslation()
{
return $this->hasOne(PageTranslation::className(), ['page_id' => 'id'])->where([
'locale' => Yii::$app->sourceLanguage
]);
}
}

0 comments on commit 2acb314

Please sign in to comment.