omgdef\multilingual\MultilingualBehavior::afterFind PHP Метод

afterFind() публичный Метод

Handle 'afterFind' event of the owner.
public afterFind ( )
    public function afterFind()
    {
        /** @var ActiveRecord $owner */
        $owner = $this->owner;
        if ($owner->isRelationPopulated('translations') && ($related = $owner->getRelatedRecords()['translations'])) {
            $translations = $this->indexByLanguage($related);
            foreach ($this->languages as $lang) {
                foreach ($this->attributes as $attribute) {
                    foreach ($translations as $translation) {
                        if ($this->getLanguageBaseName($translation->{$this->languageField}) == $lang) {
                            $attributeName = $this->localizedPrefix . $attribute;
                            $this->setLangAttribute($this->getAttributeName($attribute, $lang), $translation->{$attributeName});
                            if ($lang == $this->defaultLanguage) {
                                $this->setLangAttribute($attribute, $translation->{$attributeName});
                            }
                        }
                    }
                }
            }
        } else {
            if (!$owner->isRelationPopulated('translation')) {
                $owner->translation;
            }
            $translation = $owner->getRelatedRecords()['translation'];
            if ($translation) {
                foreach ($this->attributes as $attribute) {
                    $attribute_name = $this->localizedPrefix . $attribute;
                    $owner->setLangAttribute($attribute, $translation->{$attribute_name});
                }
            }
        }
        foreach ($this->attributes as $attribute) {
            if ($owner->hasAttribute($attribute) && $this->getLangAttribute($attribute)) {
                $owner->setAttribute($attribute, $this->getLangAttribute($attribute));
            }
        }
    }