public function actionDelete($id, $type = null)
 {
     // Find Model
     $model = FormService::findById($id);
     // Delete/Render if exist
     if (isset($model)) {
         $model->type = $type;
         if ($model->load(Yii::$app->request->post(), 'Form')) {
             if (FormService::delete($model)) {
                 $this->redirect($this->returnUrl);
             }
         }
         $templatesMap = TemplateService::getIdNameMapByType(CoreGlobal::TYPE_FORM);
         $templatesMap = ArrayHelper::merge(['0' => 'Choose Template'], $templatesMap);
         return $this->render('@cmsgears/module-core/admin/views/form/delete', ['model' => $model, 'templatesMap' => $templatesMap, 'visibilityMap' => Form::$visibilityMap]);
     }
     // Model not found
     throw new NotFoundHttpException(Yii::$app->cmgCoreMessage->getMessage(CoreGlobal::ERROR_NOT_FOUND));
 }
Beispiel #2
0
 public static function fillFromModelAttribute($formSlug, $modelAttributes)
 {
     $form = FormService::findBySlug($formSlug);
     $fieldsMap = [];
     if (isset($form)) {
         $formFields = $form->getFieldsMap();
         foreach ($formFields as $key => $formField) {
             // Convert CheckBox csv to array
             if ($formField->isCheckboxGroup()) {
                 $this->{$fieldName} = split("/,/", $formField->value);
             }
             // Ignore passwords
             if (!$formField->isPasswordField()) {
                 $formField->value = $modelAttributes[$key]->value;
             }
             $fieldsMap[$formField->name] = $formField;
         }
     }
     return $fieldsMap;
 }