Example #1
0
 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;
     }
 }
 /**
  * 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.');
     }
 }