/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new ContentTemplateWidget(); if ($model->load(Yii::$app->request->post()) && $model->convertPositionIds() && $model->save()) { return $this->redirect($this->getRedirectPage('create', $model)); } return $this->renderIsAjax('create', compact('model')); }
/** * Create ContentTemplateWidget or update it * * @inheritdoc */ public function afterSave($insert, $changedAttributes) { if ($insert) { $widget = new ContentTemplateWidget(); $widget->name = $this->name; $widget->position = $this->position; $widget->widget_class = self::WIDGET_CLASS; $widget->code = md5(__CLASS__ . '_' . $this->id); $widget->widget_options = serialize(['code' => $this->code]); $widget->has_settings = 1; $widget->link_to_settings = '/content/content-page/tree?menuId=' . $this->id; $widget->save(false); } elseif (array_key_exists('name', $changedAttributes) || array_key_exists('position', $changedAttributes) || array_key_exists('code', $changedAttributes)) { $widget = ContentTemplateWidget::findOne(['widget_class' => self::WIDGET_CLASS, 'code' => md5(__CLASS__ . '_' . $this->id)]); if ($widget) { $widget->name = $this->name; $widget->position = $this->position; $widget->widget_options = serialize(['code' => $this->code]); $widget->save(false); } } TagDependency::invalidate(Yii::$app->cache, ContentModule::CACHE_TAG); parent::afterSave($insert, $changedAttributes); }