/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Alias::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     // Join the entity model as a relation
     $query->joinWith(['entityModel' => function ($query) {
         $query->join('INNER JOIN', ['entity' => 'pages_lang'], 'pages.id = entity.page_id AND entity.language = \'' . Yii::$app->language . '\'');
     }]);
     // enable sorting for the related column
     $dataProvider->sort->attributes['entityModel.name'] = ['asc' => ['entity.name' => SORT_ASC], 'desc' => ['entity.name' => SORT_DESC]];
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['LIKE', 'entity.name', $this->getAttribute('entityModel.name')]);
     return $dataProvider;
 }
 /**
  * Deletes all aliases for the model
  *
  * @return boolean
  */
 protected function deleteAliases()
 {
     return Alias::deleteAll(['entity' => parent::className(), 'entity_id' => $this->primaryKey]);
 }
 /**
  * Finds the Alias model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return Alias the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Alias::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException(Yii::t('app', 'The requested page does not exist'));
     }
 }
 /**
  * Updates the Alias model attributes, based on data of the $_POST array
  */
 protected function updateAlias()
 {
     if (Yii::$app->request->getIsPost()) {
         $post = Yii::$app->request->post();
         $type = Alias::TYPE_USER_DEFINED;
         // Values from the $_POST array can be extracted by using the last
         // part of $this->entityType and $this->typePostKey as keys.
         $entityNameParts = explode('\\', $this->entityType);
         $entityName = array_pop($entityNameParts);
         if ($entityName && isset($post[$entityName])) {
             if (isset($post[$entityName][$this->typePostKey])) {
                 $type = $post[$entityName][$this->typePostKey];
             }
         }
         $this->alias->type = $type;
         if (isset($post[StringHelper::basename(Alias::className())][$this->alias->language]['url'])) {
             $this->alias->url = $post[StringHelper::basename(Alias::className())][$this->alias->language]['url'];
         }
     }
 }