@param null|integer $id
@param null|integer $languageId
@param string $viewName
@return mixed
@throws Exception

Loads data from post.
492465
private function loadCategory($id = null, $languageId = null, $viewName, $params = [])
    {
        $category = (!empty($id)) ? Category::findOne($id) : new Category();
        $categoryTranslation = (!empty($id)) ? CategoryTranslation::find()->where([
            'category_id' => $id,
            'language_id' => $languageId
        ])->one() : new CategoryTranslation();

        $categoryTranslation = $categoryTranslation ?? new CategoryTranslation();

        if (Yii::$app->request->isPost) {
            ($category->isNewRecord) ? $this->trigger(self::EVENT_BEFORE_CREATE_CATEGORY) :
                $this->trigger(self::EVENT_BEFORE_EDIT_CATEGORY);

            $post = Yii::$app->request->post();

            $category->load($post);
            $category->parent_id = (!empty($category->parent_id)) ? $category->parent_id : null;
            $categoryTranslation->load($post);

            if ($category->validate()) {
                $eventName = $category->isNewRecord ? self::EVENT_AFTER_CREATE_CATEGORY : self::EVENT_AFTER_EDIT_CATEGORY;

                $category->save();

                if (empty($categoryTranslation->seoUrl)) $categoryTranslation->seoUrl = Inflector::slug($categoryTranslation->title);

                $categoryTranslation->category_id = $category->id;
                $categoryTranslation->language_id = $languageId;

                if ($categoryTranslation->validate()) {
                    $categoryTranslation->save();

                    $this->trigger($eventName, new CategoryEvent(['id' => $category->id]));

                    Yii::$app->getSession()->setFlash('success', 'The category has been successfully modified.');
                    return $this->redirect([$viewName, 'id' => $category->id, 'languageId' => $languageId]);
                }
            }
        }

        return $this->render('save', [
            'viewName' => $viewName,
            'params' => array_merge([
                'languages' => Language::findAll(['active' => true]),
                'maxPosition' => Category::find()->where(['parent_id' => $category->parent_id])->max('position') + 1 ?? 1,
                'category' => $category,
                'categoryTranslation' => $categoryTranslation,
                'categories' => Category::find()->with('translations')->all(),
                'selectedLanguage' => Language::findOne($languageId),
            ], $params)
        ]);
    }
704906
public function updateSelect($id = null) {
		//$this->autoRender = false;
		if (!$this->request->is('post') || !$this->request->is('ajax')) {
			throw new Exception(__('not a valid request'));
		}
		$this->viewBuilder()->layout('ajax');
		$states = $this->States->getListByCountry($id);
		$defaultFieldLabel = 'pleaseSelect';
		if ($this->request->query('optional')) {
			$defaultFieldLabel = 'doesNotMatter';
		}

		$this->set(compact('states', 'defaultFieldLabel'));
	}
1045654
public function getTemplate($key, $language_id)
    {
        if ($template = EmailTemplateTranslation::findOne([
            'template_id' => EmailTemplate::getIdByKey($key),
            'language_id' => $language_id
        ])) {
            return Template::buildTemplate($template);
        }

        return null;
    }
1206515
protected function findOrCreateModelTranslation($id, $languageId)
    {
        $modelTranslations = OrderStatusTranslation::find()
            ->where(['order_status_id' => $id, 'language_id' => $languageId])->one();
        return (!empty($modelTranslations)) ? $modelTranslations : new OrderStatusTranslation();
    }
159179
public function single($lang, $view, $id)
    {
        $classNameArr = explode("\\", get_class($this));
        $className = str_replace("Controller", "", $classNameArr[4]);
        // if we are accessing Post Type check if we are are in category or tags and repair the class name and key for them
        $key = $view;
        if($className === "PostType") {
            if(strpos($key, 'category') !== false) {
                $className = 'Categories';
                // make categorylist to list, categoryupdate to update etc
                $key = str_replace('category', '', $key);
            }else if(strpos($key, 'tag') !== false) {
                // make taglist to list, tagupdate to update etc
                $className = 'Tags';
                $key = str_replace('tag', '', $key);
            }
        }

        $key = ($key == "list" || $key == "posts") ? 'read' : $key;
        // check if user has permissions to access this link
        if($key == 'read') {
            if(!User::hasAccess($className, $key)) {
                return view('errors.permissions', compact('lang', 'view', 'id'));
            }
        }else{
            if(!User::hasAccess($className, $key, $id, true)) {
                return view('errors.permissions', compact('lang', 'view', 'id'));
            }
        }

        return view('content');
    }
443744
public function tryLoad($id)
    {
        if (is_null($id)) {
            throw $this->exception('Record ID must be specified, otherwise use loadAny()');
        }

        return $this->_load($id, true);
    }
1136553
public function get($id)
    {
        if (empty($id)) {
            throw new \Exception('cannot load object with empty id');
        }

        $params = new RequestParams(RequestOps::GET, $this->resourceMetadata, $id);
        $jsonResponse = $this->request($params);

        if ($jsonResponse == false) {
            throw new Exception('Error retrieving data');
        }

        $inst = $this->createResourceInst($jsonResponse, $this->resourceMetadata->resourceClass);

        $this->postProcess($inst);

        return $inst;
    }
194670
public function deleteSeoAttributesFromLanguage($languageId, $pageId)
    {
        $alSeo = $this->seoRepository->fromPageAndLanguage($languageId, $pageId);
        // Occours when the attributes has been already removed
        if (null === $alSeo) return true;

        $this->set($alSeo);
        $result = $this->delete();
        $this->set(null);

        return $result;
    }
327653
public function getTagById( $id, $throwException = TRUE )
	{
		$xpath	= new DomXPath( $this->document );
		$query	= "//*[@id = '$id']";
		$tags	= $this->getTagsByXPath( $query );
		if( $tags )
			return $tags[0];
		if( $throwException )
			throw new RuntimeException( 'No Tag with ID "'.$id.'" found.' );
		return NULL;
	}
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);
        }
    }
1070293
public static function get(string $id, string $lng = '')
    {
        if (!isset(self::$cached_data[$id])) {
            $translation_obj = TranslationRepository::findOneEntityById($id);
            if ($translation_obj) {
                self::$cached_data[$id] = $translation_obj->getAsArray();
            }
        }

        if (!$lng) {
            return self::$cached_data[$id] ?? NULL;
        }

        return isset(self::$cached_data[$id], self::$cached_data[$id][$lng]) ? self::$cached_data[$id][$lng] : NULL;
    }
215988
public function delete(string $id = null)
    {
        $this->request->allowMethod(['post', 'delete']);
        $translation = $this->Translations->get($id);
        if ($this->Translations->delete($translation)) {
            $this->Flash->success((string)__('The translation has been deleted.'));
        } else {
            $this->Flash->error((string)__('The translation could not be deleted. Please, try again.'));
        }

        return $this->redirect(['action' => 'index']);
    }
1048727
public function loadLanguageById($languageId)
    {
        $language = $this->languageHandler->load($languageId);

        return $this->buildDomainObject($language);
    }
1037402
public function newRevision($language_id = null)
    {
        $created = new static($language_id ?: $this->language_id);
        $created->content = $this->content;

        return $created;
    }
901992
public function translationByLanguageID( $languageID )
    {
        /** @var eZContentLanguage $language */
        $language = eZContentLanguage::fetch( $languageID );
        if ( $language instanceof eZContentLanguage )
            return $this->translationByLocale( $language->attribute( 'locale' ) );

        return false;
    }
339089
public function run($id = null, $contextId = null)
    {
        Yii::$app->response->format = Response::FORMAT_JSON;
        if (false === Yii::$app->user->can('dotplant-structure-view')) {
            throw new ForbiddenHttpException(Yii::t(
                'yii', 'You are not allowed to perform this action.'
            ));
        }
        /** @var BaseStructure | string $class */
        if (null === $current_selected_id = Yii::$app->request->get($this->querySelectedAttribute)) {
            $current_selected_id = Yii::$app->request->get($this->queryParentAttribute);
        }
        $checked = Yii::$app->request->get('checked', '');
        $cacheKey = "AdjacencyFullTreeData:{$this->cacheKey}:{$this->querySortOrder}:{$id}:{$contextId}"
            . Yii::$app->multilingual->language_id . $this->showHiddenInTree . $checked;
        if (false === empty($checked)) {
            $checked = explode(',', $checked);
        } else {
            $checked = [];
        }
        if (false === $result = Yii::$app->cache->get($cacheKey)) {
            $contexts = call_user_func([Yii::$app->multilingual->modelsMap['Context'], 'getListData']);
            /** @var ActiveQuery $query */
            $parentId = ('#' == $id) ? null : $id;
            $query = BaseStructure::find()
                ->where(['parent_id' => $parentId])
                ->orderBy([
                    $this->contextIdAttribute => SORT_ASC,
                    $this->querySortOrder => SORT_ASC
                ]);
            if (count($this->whereCondition) > 0) {
                $query = $query->where($this->whereCondition);
            }
            if ($contextId != 'all') {
                $query->andWhere([$this->contextIdAttribute => $contextId]);
            }

            $entityId = (null !== $this->className) ? Entity::getEntityIdForClass($this->className) : null;
            if (null === $rows = $query->asArray()->all()) {
                return [];
            }
            $result = [];
            $hidden = [];
            $roots = BaseStructure::find()->select(['id'])->where(['is_deleted' => 1])->column();
            $hidden += $roots;
            foreach ($roots as $id) {
                self::treeGoDown($id, $rows, $hidden);
            }
            foreach ($rows as $row) {
                if ((int)$row['expand_in_tree'] === 1) {
                    $c = (new Query())
                        ->from(BaseStructure::tableName())
                        ->where(['parent_id' => $row['id']])
                        ->select('id')
                        ->count();
                    $children = $c > 0;
                } else {
                    $children = false;
                }
                $item = [];
                if (true === in_array($row[$this->modelIdAttribute], $hidden)) {
                    if (true === $this->showHiddenInTree) {
                        self::setState($item, ['disabled' => true]);
                    } else {
                        continue;
                    }
                }
                $text = ($row[$this->modelParentAttribute] > 0)
                    ? $row['defaultTranslation'][$this->modelLabelAttribute]
                    : ($row['defaultTranslation'][$this->modelLabelAttribute]
//                        . " ({$contexts[$row[$this->contextIdAttribute]]})"
                    );
                $item += [
                    'id' => $row[$this->modelIdAttribute],
                    'parent' => ($row[$this->modelParentAttribute] > 0) ? $row[$this->modelParentAttribute] : '#',
                    'text' => $text,
                    'children' => $children,
                    'a_attr' => [
                        'data-id' => $row[$this->modelIdAttribute],
                        'data-parent_id' => $row[$this->modelParentAttribute],
                        'data-context_id' => $row[$this->contextIdAttribute],
                        'data-entity_id' => $row['entity_id'],
                    ],
                ];
                if (null !== $entityId && $entityId != $row['entity_id']) {
                    self::setState($item, ['checkbox_disabled' => true]);
                }
                if (true === in_array($row[$this->modelIdAttribute], $checked)) {
                    self::setState($item, ['opened' => true, 'checked' => true, 'selected' => true]);
                }
                if (null !== $this->varyByTypeAttribute) {
                    $item['type'] = $row[$this->varyByTypeAttribute];
                }
                $result[$row[$this->modelIdAttribute]] = $item;
            }

            Yii::$app->cache->set(
                $cacheKey,
                $result,
                86400,
                new TagDependency([
                    'tags' => [
                        NamingHelper::getCommonTag(BaseStructure::class),
                    ],
                ])
            );
        }

        if (array_key_exists($current_selected_id, $result)) {
            $result[$current_selected_id] = array_merge(
                $result[$current_selected_id],
                ['state' => ['opened' => true, 'selected' => true]]
            );
        }

        return array_values($result);
    }
756283
public function actionEdit($id = null)
    {
        if ($id === null) {
            $model = new CountryLanguage;
        } else {
            $model = $this->findModel($id);
        }
        $isLoaded = $model->load(Yii::$app->request->post());
        $hasAccess = ($model->isNewRecord && Yii::$app->user->can('multilingual-create-country-language'))
            || (!$model->isNewRecord && Yii::$app->user->can('multilingual-edit-country-language'));
        if ($isLoaded && !$hasAccess) {
            throw new ForbiddenHttpException;
        }
        if ($isLoaded && $model->save()) {
            return $this->redirect(['edit', 'id' => $model->id]);
        } else {
            return $this->render(
                'edit',
                [
                    'hasAccess' => $hasAccess,
                    'model' => $model,
                ]
            );
        }
    }