/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = GroupField::find(); // add conditions that should always apply here $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } // grid filtering conditions $query->andFilterWhere(['id' => $this->id, 'group_field_order' => $this->group_field_order, 'group_field_position' => $this->group_field_position, 'group_field_style' => $this->group_field_style, 'group_field_status' => $this->group_field_status]); $query->andFilterWhere(['like', 'group_field_name', $this->group_field_name])->andFilterWhere(['like', 'group_field_description', $this->group_field_description]); return $dataProvider; }
<?php $form = ActiveForm::begin(['id' => 'post-create-form', 'options' => ['class' => 'post-create']]); ?> <div class="row"> <div class="wrapper wrapper-content animated fadeInRight"> <div class="col-md-8"> <?php echo $this->render('partials/_form', ['model' => $model, 'form' => $form]); ?> <?php echo $groupField = GroupField::renderFields(GroupField::POSITION_TAB, $postType->id, $model); ?> <?php echo $this->render('partials/_form-comment', ['model' => $model, 'form' => $form]); ?> <?php echo $this->render('partials/_meta-box', ['model' => $model, 'form' => $form, 'postType' => $postType]); ?> </div> <div class="col-md-4"> <?php
public static function renderFields($position, $postType, Post $model) { $html = ''; $tabItems = []; $groupFieldIds = GroupFieldRule::canRender($postType); if ($groupFieldIds) { foreach ($groupFieldIds as $groupFieldId) { $groupField = GroupField::findOne($groupFieldId); //We only render the Group Field if its position is equal to the given position //And if the position is tab the fields should be in a Tab component. if ($groupField->group_field_position == $position) { $customFields = $groupField->customFields; switch ($position) { case self::POSITION_TAB: $tabItems[] = self::makeTabItems($groupField, $customFields, $model); break; default: $html .= self::makeFormElements($customFields, $model); break; } } } } if (!empty($tabItems)) { return self::makeTabElement($tabItems); } else { return $html; } }
<?php $form = ActiveForm::begin(['id' => 'post-create-form', 'options' => ['class' => 'post-create']]); ?> <div class="row"> <div class="wrapper wrapper-content animated fadeInRight"> <div class="col-md-8"> <?php echo $this->render('partials/_form', ['model' => $model, 'form' => $form]); ?> <?php echo $groupField = GroupField::renderFields(GroupField::POSITION_TAB, $model->post_type, $model); ?> <?php echo $this->render('partials/_form-comment', ['model' => $model, 'form' => $form]); ?> <?php echo $this->render('partials/_meta-box', ['model' => $model, 'form' => $form, 'postType' => $postType]); ?> </div> <div class="col-md-4"> <?php echo $this->render('partials/_form-publish', ['model' => $model, 'form' => $form]); ?>
/** * @return \yii\db\ActiveQuery */ public function getGroupField() { return $this->hasOne(GroupField::className(), ['id' => 'group_field_id']); }
/** * Finds the GroupField model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return GroupField the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = GroupField::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }