creocoder\translateable\TranslateableBehavior::hasTranslation PHP Method

hasTranslation() public method

Returns a value indicating whether the translation model for the specified language exists.
public hasTranslation ( string | null $language = null ) : boolean
$language string | null
return boolean
    public function hasTranslation($language = null)
    {
        if ($language === null) {
            $language = Yii::$app->language;
        }
        /* @var ActiveRecord $translation */
        foreach ($this->owner->{$this->translationRelation} as $translation) {
            if ($translation->getAttribute($this->translationLanguageAttribute) === $language) {
                return true;
            }
        }
        return false;
    }

Usage Example

Esempio n. 1
0
 /**
  * @inherited
  */
 public function hasTranslation($language = null)
 {
     if ($language === null) {
         $language = Lang::getCurrent()->id;
     }
     return parent::hasTranslation($language);
 }