/** * @return \yii\db\ActiveQuery */ public function getWidgets() { /** @var \yii\db\ActiveQuery $query */ $query = Widget::find()->select(['{{%widgets}}.*', '{{%widget_area_widgets}}.sort AS sort'])->innerJoin('{{%widget_area_widgets}}', '{{%widgets}}.id = {{%widget_area_widgets}}.widget_id AND {{%widget_area_widgets}}.widget_area_id = :id', ['id' => $this->id])->orderBy(['{{%widget_area_widgets}}.sort' => SORT_ASC]); $query->multiple = true; return $query; }
/** * Gets widgets from data array. * * @param array $data * @param string $formName * @return Widget[] */ protected function getWidgets($data, $formName) { $widgets = []; if (!empty($data[$formName])) { /** @var LayoutManager $layoutManager */ $layoutManager = Yii::$app->get('layoutManager'); $pks = []; foreach ($data[$formName] as $area => $areaWidgets) { foreach ($areaWidgets as $sort => $widgetData) { if (!empty($widgetData['id'])) { $pks[] = $widgetData['id']; } elseif (!empty($widgetData['type'])) { $widgets[$area][$sort] = $layoutManager->getWidgetInstance($widgetData['type']); } } } if ($pks) { $widgets = $widgets + Widget::find()->where(['id' => $pks])->indexBy('id')->all(); } } return $widgets; }
/** * @inheritdoc */ public function rules() { return array_merge(parent::rules(), [[['content'], 'required']]); }
/** * @inheritdoc */ public function rules() { return array_merge(parent::rules(), [[['banner_id'], 'safe']]); }