/** * 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); }