You are here

public function DataSourceDefinitionForm::submitForm in Forena Reports 8

[@inheritdoc}

Overrides FormInterface::submitForm

File

src/Form/DataSourceDefinitionForm.php, line 314

Class

DataSourceDefinitionForm

Namespace

Drupal\forena\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $values = $form_state
    ->getValues();
  $storage = $form_state
    ->getStorage();
  $name = $values['name'];
  $config = $storage['config'];
  $config['source'] = @$values['source'];
  $config['driver'] = $values['driver'];
  $config['user callback'] = $values['user_callback'];
  $config['debug'] = $values['debug'];
  if (@$values['connection']['new_password']) {
    $values['connection']['password'] = $values['connection']['new_password'];
  }
  if (isset($values['connection']['new_password'])) {
    unset($values['connection']['new_password']);
  }
  if (is_array(@$values['connection'])) {
    $config = array_merge($config, @$values['connection']);
  }
  if ($values['access_method'] == 'callback') {
    $config['access callback'] = empty($values['access_callback']) ? 'forena_user_access_check' : $values['access_callback'];
    if (isset($config['access block'])) {
      unset($config['access block']);
    }
  }
  else {
    $config['access block'] = $values['access_block'];
  }
  $config_str = serialize($config);
  $result = db_query('SELECT * FROM {forena_repositories} WHERE repository = :name', array(
    ':name' => $name,
  ));
  if ($repos = $result
    ->fetchObject()) {
    db_update('forena_repositories')
      ->fields(array(
      'title' => $values['title'],
      'enabled' => $values['enabled'],
      'config' => $config_str,
    ))
      ->condition('repository', $name, '=')
      ->execute();
  }
  else {
    db_insert('forena_repositories')
      ->fields(array(
      'repository' => $name,
      'title' => $values['title'],
      'enabled' => $values['enabled'],
      'config' => $config_str,
    ))
      ->execute();
  }
  drupal_set_message(t('The configuration options have been saved.'));
}