Render text block by id,
For runAction() at template only.
@param string|integer $id
@param string $lang
@param string $params additional params - only string - need serialize for array
@return string  result text or '' on any error
184641
public function actionRender($id, $lang = null, $params = '')
    {
        if (empty($lang)) $lang = Yii::$app->language;
        $langHelper = $this->module->langHelper;
        $lang = $langHelper::normalizeLangCode($lang);

        if (is_numeric($id)) {
            $contentId = $id;
        } else {
            $contentId = $this->model->getIdBySlugPath($id);
        }

        if (empty($contentId)) {
            $msg = __METHOD__ . ": illegal id = '$id'.";
            Yii::error($msg);
            return '';
        }
        $node = $this->model->node($contentId);
        if (empty($node)) {
            $msg = __METHOD__ . ": node id='{$contentId}' not found.";
            Yii::error($msg);
            return '';
        }

        if (isset($node->i18n[$lang]->text)) {
            if ($node->is_visible) {
                $text = $node->i18n[$lang]->text;
            } else {
                $text = '';
                $msg = __METHOD__ . ": for node id='{$contentId}' disable visibility.";
                Yii::trace($msg);
                return '';
            }
        } else {
            $msg = __METHOD__ . ": for node id='{$contentId}', lang='$lang' not found text.";
            Yii::error($msg);
            return '';
        }

        // processing parameters in format '{{param}}', translation table get from unserialized $params
        $defParams = $this->getDefaultParams($node, $lang);
        $params = @unserialize($params);
        if (!is_array($params)) { // $params must be array (on error unserialize() return false)
            $params = [];
        }
        $params = ArrayHelper::merge($defParams, $params);
        $text = TextProcessor::textPreprocess($text, $params);
        return $text;
    }
1303249
public function actionView($id)
    {
        $model = $this->findModel($id);
        $modelsI18n = $model->prepareI18nModels();

        if ($model->pageSize > 0) {
            $model->orderBy = $model::$defaultOrderBy;
            $model->page = $model->calcPage();
        }

        // build frontend links
        $lh = $this->module->langHelper;
        $editAllLanguages = empty($this->module->params['editAllLanguages'])
                          ? false : $this->module->params['editAllLanguages'];
        $languages = $lh::activeLanguages($editAllLanguages);
        if (Yii::$app instanceof UniApplication && Yii::$app->type == UniApplication::APP_TYPE_BACKEND) {
            $containerModule = $this->module->module;
            if ($containerModule instanceof UniModule && array_key_exists(static::$sysAppModel, $containerModule->models)) {
                $appModel = $containerModule::model(static::$sysAppModel);
                $appFront = $appModel::initFrontendApplication();  // for backend application init separate frontend-application
              //$appFront->urlManager->baseUrl = 'http://www.mysite.com';  // frontend domain - set from app-params
            }
        }
        $moduleUid = $this->module->uniqueId;
        $frontendLinks = [];
        foreach ($languages as $langCode => $lang) {
            $frontendLinks[$langCode] = '';
            if ($model->hasInvisibleParent()) {
                if (empty($model->route)) {
                    $frontendLinks[$langCode] = Url::toRoute(["/{$moduleUid}/main/show", 'id' => $model->id, 'slug' => $model->slug]);
                } else {  // external/internal link
                    $frontendLinks[$langCode] = ContentMenuBuilder::routeToLink($model->route);
                }
            } else {
                $frontendLinks[$langCode] = Url::toRoute(["/{$moduleUid}/main/view"
                  , 'id' => $model->id, 'lang' => $langCode], true);
            }
        }
        if (!empty($appModel)) $appModel::restoreApplication();

        return $this->render('view', compact('model', 'modelsI18n', 'frontendLinks'));
    }
45320
public function getBatchUserInfo(array $openids, $lang = 'zh_CN')
    {
        $url = 'https://api.weixin.qq.com/cgi-bin/user/info/batchget?access_token=ACCESS_TOKEN';
        $data = ['user_list' => []];
        foreach ($openids as $openid) {
            $data['user_list'][] = ['openid' => $openid, 'lang' => $lang];
        }
        $this->registerApi($url, __FUNCTION__, func_get_args());
        return $this->httpPostForJson($url, $data);
    }
11098
public function deleteLanguage($id)
    {
        try {
            return $this->innerGateway->deleteLanguage($id);
        } catch (DBALException $e) {
            throw new RuntimeException('Database error', 0, $e);
        } catch (PDOException $e) {
            throw new RuntimeException('Database error', 0, $e);
        }
    }
539738
public function actionDeleteLanguage($id)
    {
        $model = $this->findLanguageModel($id);
        $model->delete();
        return $this->redirect(['edit', 'id' => $model->context_id]);
    }
541274
public static function render($xml, array $params = [])
	{
		$renderer = static::getCachedRenderer();

		if (!empty($params))
		{
			$renderer->setParameters($params);
		}

		if (isset(static::$beforeRender))
		{
			$xml = call_user_func(static::$beforeRender, $xml);
		}

		$output = $renderer->render($xml);

		if (isset(static::$afterRender))
		{
			$output = call_user_func(static::$afterRender, $output);
		}

		return $output;
	}
675843
public function translate($id, $params = null, $domain = null, $locale = null) {
		if ($domain === null) {
			$domain = $this->handleDomain($id);
		}
		
		if ($locale === null) {
			$locale = $this->getLocale();
		} else {
			$locale = $this->normalizeLocale($locale);
		}
		
		$translation = $this->getTranslation($id, $domain, $locale, $this->fallbackLocales);
		
		if ($translation === null) {
			return $this->handleFailure($id);
		}
		
		if (! empty($this->plugins)) {
			$translation = $this->handlePlugins($locale, $translation, $params);
		}
		
		if ($params === null) {
			return $translation;
		}
		
		return strtr($translation, $this->normalizeParams($params));
	}
1159592
public function update(string $id, array $params = [])
    {
        return $this->executeRequest(
            RequestMethodEnum::PUT,
            ResourceMethodEnum::UPDATE,
            $params,
            $id
        );
    }
1315768
static void render(FacesContext context, final Set<String> ids) {
        if (ids.isEmpty()) {
            return;
        }
        final Collection<String> renderIds = context.getPartialViewContext().getRenderIds();
        final char separatorChar = getSeparatorChar(context);
        for (String id : ids) {
            renderIds.add(id.substring(id.indexOf(separatorChar) + 1));
        }
    }
907562
public function actionEditLanguage($id = null, $contextId = null)
    {
        if ($id === null) {
            $model = new Language();
        } else {
            $model = $this->findLanguageModel($id);
        }
        if ($contextId !== null) {
            $model->context_id = $contextId;
        }
        $hasAccess = ($model->isNewRecord && Yii::$app->user->can('multilingual-create-language'))
            || (!$model->isNewRecord && Yii::$app->user->can('multilingual-edit-language'));
        $isLoaded = $model->load(Yii::$app->request->post());
        if ($isLoaded && !$hasAccess) {
            throw new ForbiddenHttpException;
        }
        if ($isLoaded && $model->save()) {
            return $this->redirect(['edit-language', 'id' => $model->id]);
        } else {
            return $this->render(
                'edit-language',
                [
                    'hasAccess' => $hasAccess,
                    'model' => $model,
                ]
            );
        }
    }
1189043
protected function _addLanguage( MW_Container_Content_Interface $contentItem, $langid, array $ids )
	{
		$manager = MShop_Catalog_Manager_Factory::createManager( $this->_getContext() );

		foreach( $ids as $id )
		{
			foreach( $this->_getNodeList( $manager->getTree( $id, array('text') ) ) as $item ) {
				$this->_addItem( $contentItem, $item, $langid );
			}
		}
	}
691736
final protected function trans($id, array $parameters = [], $domain = null, $locale = null)
    {
        $domain = $domain ?: $this->admin->getTranslationDomain();

        return $this->get('translator')->trans($id, $parameters, $domain, $locale);
    }
668817
public function createForTask(string $id, array $params = [])
    {
        return $this->executeRequest(
            RequestMethodEnum::POST,
            ResourceMethodEnum::CREATE_FOR_TASK,
            $params,
            $id
        );
    }
556641
protected function script($id, $params)
    {
        $handler       = $this->handler = 'handler' . str_random(4);
        $options       = array_replace_recursive($this->defaults()['pluginOptions'], $params['pluginOptions']);
        $decorated     = JavaScriptDecorator::decorate($options);
        return $this->init($id) . $handler . '.' . $this->pluginName . '(' . $decorated . ')';
    }
1036189
public function getText(string $id): ?string
    {
        $getText = function(string $id, string $locale) {
            if (isset($this->defaultLocales[$locale]) && $this->defaultLocales[$locale] === 0) {
                $app = App::get();
                $context = $app->contexts->get(__FILE__);
                $this->defaultLocales[$locale] = 1;
                $filename = $context->dir . '/locales/' . $locale . '.php';
                if (is_file($filename)) {
                    $data = include $filename;
                    if (is_array($data)) {
                        $this->addDictionary($locale, $data);
                    }
                }
            }
            if (isset($this->dictionaries[$locale])) {
                foreach ($this->dictionaries[$locale] as $i => $dictionary) {
                    if (is_callable($dictionary)) {
                        $dictionary = call_user_func($dictionary);
                        $this->dictionaries[$locale][$i] = $dictionary;
                    }
                    if (is_array($dictionary)) {
                        foreach ($dictionary as $_id => $text) {
                            if ($id === $_id) {
                                return (string) $text;
                            }
                        }
                    }
                }
            }
            return null;
        };
        $text = $getText($id, $this->locale);
        if ($text === null || !isset($text[0])) {
            $text = $getText($id, $this->backupLocale);
        }
        return $text;
    }
1153996
public function translateAction(Request $request, $id, $locale)
    {
        /** @var PageInterface $page */
        $page = $this->admin->getObject($id);

        if (!$page) {
            throw new NotFoundHttpException(sprintf('unable to find the object with id : %s', $id));
        }
        $language = \Locale::getDisplayLanguage($locale);

        if ($request->getMethod() == 'POST') {
            $pageHelper = $this->container->get('networking_init_cms.helper.page_helper');

            try {
                $pageCopy = $pageHelper->makeTranslationCopy($page, $locale);
                $this->admin->createObjectSecurity($pageCopy);
                $status = 'success';
                $message = $this->translate(
                    'message.translation_saved',
                    ['%language%' => $language]
                );
                $result = 'ok';
                $html = $this->renderView(
                    '@NetworkingInitCms/PageAdmin/page_translation_settings.html.twig',
                    ['object' => $page, 'admin' => $this->admin]
                );
            } catch (\Exception $e) {
                $status = 'error';
                $message = $message = $this->translate(
                    'message.translation_not_saved',
                    ['%language%' => $language, '%url%' => $page->getFullPath()]
                );
                $result = 'error';
                $html = '';
            }

            if ($this->isXmlHttpRequest()) {
                return $this->renderJson(
                    [
                        'result' => $result,
                        'status' => $status,
                        'html' => $html,
                        'message' => $message,
                    ]
                );
            }

            $this->get('session')->getFlashBag()->add(
                'sonata_flash_'.$status,
                $message
            );

            return $this->redirect($this->admin->generateUrl('edit', ['id' => $id]));
        }

        return $this->render(
            '@NetworkingInitCms/PageAdmin/page_translation_copy.html.twig',
            [
                'action' => 'copy',
                'page' => $page,
                'id' => $id,
                'locale' => $locale,
                'language' => $language,
                'admin' => $this->admin,
            ]
        );
    }
868590
public function generateFieldSlug($lang, $key, $id, $keys)
    {
        $count = 1;
        $found = true;
        $slug = str_slug($key, '_');

        $keysArray = array();
        foreach ($keys as $key){
            if($id != $key['id']) {
                $keysArray[] = $key['slug'];
            }
        }

        if(!in_array($slug, $keysArray) && !in_array($slug, $this->usedSlugs)) {
            return $slug;
        }else{
            while ($found){
                $newSlug = $slug.'_'.$count;
                if(!in_array($newSlug, $keysArray) && !in_array($newSlug, $this->usedSlugs)) {
                    $found = false;
                    $this->usedSlugs[] = $newSlug;
                    return $newSlug;
                }
                $count++;
            }
        }

        return $keysArray;
    }