models/News.php
public static function prepareI18nModels($model)
    {//echo __METHOD__;var_dump($model->attributes);
        //$languages = LangHelper::activeLanguages();//var_dump($languages);
        //$config = Module::getModuleConfigByClassname(Module::className());//var_dump($config);
        //$langHelper = $config['params']['langHelper'];

        $moduleClass = static::moduleClass();//var_dump($module);exit;
        if (!$moduleClass) $moduleClass = Module::className(); //?? or better throw new \Exception("Can't found module for " . static::className());
        $module = UniModule::getModuleByClassname($moduleClass);

        $langHelper = $module->langHelper;
        //$languages = $langHelper::activeLanguages();//var_dump($languages);
        $editAllLanguages = empty($module->params['editAllLanguages']) ? false : $module->params['editAllLanguages'];
        $languages = $langHelper::activeLanguages($editAllLanguages);//var_dump($languages);exit;

        $mI18n = $model->i18n;//var_dump($mI18n);exit;

        //$conf = Module::getModuleConfigByClassname(Module::className());//var_dump($conf);
        //$contentHelperClass = $conf['params']['contentHelper'];
        //$module = Module::getModuleByClassname(Module::className());
        //$contentHelperClass = $module->contentHelper;
        //$contentHelper = new $contentHelperClass;

        $modelsI18n = [];
        foreach ($mI18n as $modelI18n) {//var_dump($modelI18n->attributes);
            //$modelI18n->body = $contentHelper::afterSelectBody($modelI18n->body); //!! move to self::correctI18nBodies()
            $modelsI18n[$modelI18n->lang_code] = $modelI18n;
        }
        $modelsI18n = static::correctI18nBodies($modelsI18n);//var_dump($modelsI18n);exit;

        foreach ($languages as $langCode => $lang) {
            if (empty($modelsI18n[$langCode])) {
                //$modelsI18n[$langCode] = (new NewsI18n())->loadDefaultValues();
                $newNewsI18n = $module::model('NewsI18n');//var_dump($newNewsI18n);exit;
                $modelsI18n[$langCode] = $newNewsI18n->loadDefaultValues();
                $modelsI18n[$langCode]->lang_code = $langCode;
            }
        }//var_dump($modelsI18n);exit;
        return $modelsI18n;
    }
public static function prepareI18nModels($model)
    {//echo __METHOD__;var_dump($model->attributes);
        //$languages = LangHelper::activeLanguages();//var_dump($languages);
        //$config = Module::getModuleConfigByClassname(Module::className());//var_dump($config);
        //$langHelper = $config['params']['langHelper'];

        $moduleClass = static::moduleClass();//var_dump($module);exit;
        if (!$moduleClass) $moduleClass = Module::className(); //?? or better throw new \Exception("Can't found module for " . static::className());
        $module = UniModule::getModuleByClassname($moduleClass);

        $langHelper = $module->langHelper;
        //$languages = $langHelper::activeLanguages();//var_dump($languages);
        $editAllLanguages = empty($module->params['editAllLanguages']) ? false : $module->params['editAllLanguages'];
        $languages = $langHelper::activeLanguages($editAllLanguages);//var_dump($languages);exit;

        $mI18n = $model->i18n;//var_dump($mI18n);exit;

        //$conf = Module::getModuleConfigByClassname(Module::className());//var_dump($conf);
        //$contentHelperClass = $conf['params']['contentHelper'];
        //$module = Module::getModuleByClassname(Module::className());
        //$contentHelperClass = $module->contentHelper;
        //$contentHelper = new $contentHelperClass;

        $modelsI18n = [];
        foreach ($mI18n as $modelI18n) {//var_dump($modelI18n->attributes);
            //$modelI18n->body = $contentHelper::afterSelectBody($modelI18n->body); //!! move to self::correctI18nBodies()
            $modelsI18n[$modelI18n->lang_code] = $modelI18n;
        }
        $modelsI18n = static::correctI18nBodies($modelsI18n);//var_dump($modelsI18n);exit;

        foreach ($languages as $langCode => $lang) {
            if (empty($modelsI18n[$langCode])) {
                //$modelsI18n[$langCode] = (new NewsI18n())->loadDefaultValues();
                $newNewsI18n = $module::model('NewsI18n');//var_dump($newNewsI18n);exit;
                $modelsI18n[$langCode] = $newNewsI18n->loadDefaultValues();
                $modelsI18n[$langCode]->lang_code = $langCode;
            }
        }//var_dump($modelsI18n);exit;
        return $modelsI18n;
    }
public static function prepareI18nModels ( $ model ) { //echo __METHOD__;var_dump($model->attributes); //$languages = LangHelper::activeLanguages();//var_dump($languages); //$config = Module::getModuleConfigByClassname(Module::className());//var_dump($config); //$langHelper = $config['params']['langHelper']; $ moduleClass = static :: moduleClass ( ) ; //var_dump($module);exit; if ( ! $ moduleClass ) $ moduleClass = Module :: className ( ) ; //?? or better throw new \Exception("Can't found module for " . static::className()); $ module = UniModule :: getModuleByClassname ( $ moduleClass ) ; $ langHelper = $ module -> langHelper ; //$languages = $langHelper::activeLanguages();//var_dump($languages); $ editAllLanguages = empty ( $ module -> params [ 'editAllLanguages' ] ) ? false : $ module -> params [ 'editAllLanguages' ] ; $ languages = $ langHelper :: activeLanguages ( $ editAllLanguages ) ; //var_dump($languages);exit; $ mI18n = $ model -> i18n ; //var_dump($mI18n);exit; //$conf = Module::getModuleConfigByClassname(Module::className());//var_dump($conf); //$contentHelperClass = $conf['params']['contentHelper']; //$module = Module::getModuleByClassname(Module::className()); //$contentHelperClass = $module->contentHelper; //$contentHelper = new $contentHelperClass; $ modelsI18n = [ ] ; foreach ( $ mI18n as $ modelI18n ) { //var_dump($modelI18n->attributes); //$modelI18n->body = $contentHelper::afterSelectBody($modelI18n->body); //!! move to self::correctI18nBodies() $ modelsI18n [ $ modelI18n -> lang_code ] = $ modelI18n ; } $ modelsI18n = static :: correctI18nBodies ( $ modelsI18n ) ; //var_dump($modelsI18n);exit; foreach ( $ languages as $ langCode => $ lang ) { if ( empty ( $ modelsI18n [ $ langCode ] ) ) { //$modelsI18n[$langCode] = (new NewsI18n())->loadDefaultValues(); $ newNewsI18n = $ module :: model ( 'NewsI18n' ) ; //var_dump($newNewsI18n);exit; $ modelsI18n [ $ langCode ] = $ newNewsI18n -> loadDefaultValues ( ) ; $ modelsI18n [ $ langCode ] -> lang_code = $ langCode ; } } //var_dump($modelsI18n);exit; return $ modelsI18n ; }
Prepare multilang models array.
@return array of NewsI18n
Prepare multilang models array .