Example #1
0
 /**
  * @return Configuration[]
  */
 public function getModels()
 {
     if (null === $this->models) {
         $models = [];
         foreach ($this->getKeys() as $key) {
             $model = Configuration::findOne($key);
             if (!$model) {
                 // create model if it is not created yet
                 $model = new Configuration();
                 $model->id = $key;
                 $model->type = Configuration::TYPE_STRING;
                 $model->preload = 0;
                 $model->published = 1;
             }
             $models[$key] = $model;
         }
         $this->models = $models;
     }
     return $this->models;
 }
Example #2
0
 /**
  * @return string
  */
 public function actionGetForm()
 {
     $post = \Yii::$app->request->post();
     $id = $post[(new Configuration())->formName()]['id'];
     $model = Configuration::findOne($id);
     if (!$model) {
         $model = new Configuration();
     }
     $model->load(\Yii::$app->request->post());
     $model->value = null;
     /** @var ConfigurationTranslation[] $translationModels */
     $translationModels = $model->getTranslationModels();
     foreach ($translationModels as $languageModel) {
         $languageModel->value = null;
     }
     //Save model for setting actual scenario in translation model
     if (!$model->isNewRecord) {
         $model->save(false);
     }
     return Json::encode(['replaces' => [['what' => '.menu-form', 'data' => $this->renderAjax('//templates/_form', ['model' => $model, 'action' => \Yii::$app->request->post('action', '')])]]]);
 }