You are here

function FormDefaultsHelper::saveForm in Form Defaults 8

File

src/Helper/FormDefaultsHelper.php, line 13

Class

FormDefaultsHelper
@class FormDefaultHelper

Namespace

Drupal\Formdefaults\Helper

Code

function saveForm($formid, $form_array) {
  $old_form = formdefaults_getform($formid);

  // Change the input format from d6 style to d7 style.
  // Keep until D8.
  foreach ($form_array as $key => $control) {
    if (isset($control['format']) && !isset($control['input_format'])) {
      $form_array[$key]['input_format'] = $control['format'];
      unset($form_array[$key]['format']);
    }
  }
  $form_data = serialize($form_array);
  if ($form_data && $form_array) {
    if ($old_form) {
      Database::getConnection()
        ->update('formdefaults_forms')
        ->condition('formid', $formid)
        ->fields(array(
        'formdata' => $form_data,
      ))
        ->execute();
    }
    else {
      Database::getConnection()
        ->insert('formdefaults_forms')
        ->fields(array(
        'formid' => $formid,
        'formdata' => $form_data,
      ))
        ->execute();
    }
  }
  else {
    $this
      ->deleteForm($formid);
  }
}