Skip to content

Commit

Permalink
DKAN-4291 Add MySQL Import settings page.
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve Wirt authored and Steve Wirt committed Sep 17, 2024
1 parent c104b61 commit 01f1300
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ description: Provides a MySQL Importer class.
type: module
core_version_requirement: ^10
package: DKAN
configure: datastore.mysql_import.settings
dependencies:
- dkan:common
- dkan:datastore
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
datastore_mysql_import.settings_form:
title: MySQl Import settings
description: Setting for the MySQL Importer.
parent: system.admin_dkan
route_name: datastore.mysql_import.settings
weight: 15
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
datastore.mysql_import.settings:
path: '/admin/dkan/datastore/mysql_import'
defaults:
_title: 'MySQL Import Settings'
_form: 'Drupal\datastore_mysql_import\Form\DatastoreMysqlImportSettingsForm'
requirements:
_permission: 'administer site configuration'
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

namespace Drupal\datastore_mysql_import\Form;

use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Datastore MySQL Import settings form.
*
* @package Drupal\datastore\Form
* @codeCoverageIgnore
*/
class DatastoreMysqlImportSettingsForm extends ConfigFormBase {


/**
* Constructs form.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory
* The factory for configuration objects.
*/
public function __construct(ConfigFactoryInterface $config_factory) {
parent::__construct($config_factory);
}

/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('config.factory'),
);
}

/**
* {@inheritdoc}
*/
public function getFormId() {
return 'datastore_mysql_import_settings_form';
}

/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return ['datastore.mysql_import.settings'];
}

/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this->config('datastore.mysql_import.settings');
$form['remove_empty_rows'] = [
'#type' => 'checkbox',
'#title' => $this->t('Enable removal of empty rows in dataset.'),
'#description' => $this->t('Unlike the chunk harvester, which ignores empty rows in a CSV, the MySQL importer will import empty rows.'),
'#default_value' => $config->get('remove_empty_rows'),
];
return parent::buildForm($form, $form_state);
}

/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->config('datastore.mysql_import.settings')
->set('remove_empty_rows', $form_state->getValue('remove_empty_rows'))
->save();
parent::submitForm($form, $form_state);
}

}

0 comments on commit 01f1300

Please sign in to comment.