function gdpr_dump_settings_form in General Data Protection Regulation 7
Gdpr dump settings form.
1 string reference to 'gdpr_dump_settings_form'
- gdpr_dump_menu in modules/
gdpr_dump/ gdpr_dump.module - Implements hook_menu().
File
- modules/
gdpr_dump/ gdpr_dump.module, line 26 - Module file for the GDPR Sql-Dump module.
Code
function gdpr_dump_settings_form($form, &$form_state) {
$form['#tree'] = TRUE;
$form['description'] = [
'#markup' => t('Apply anonymization for each table columns containing sensitive data!'),
];
$form['tables'] = [
'#type' => 'container',
];
$plugins = [];
// @todo: implement sanitize plugins
foreach (gdpr_dump_get_sanitizer_plugins() as $plugin_name => $plugin) {
$plugins[$plugin_name] = $plugin['title'];
}
$sanitationOptions = [
'#type' => 'select',
'#title' => t('Sanitation plugin'),
'#options' => $plugins,
'#empty_value' => 'none',
'#empty_option' => t('- No -'),
'#title_display' => 'invisible',
];
$mapping = variable_get('gdpr_dump_table_map', []);
$empty_tables = variable_get('gdpr_dump_empty_tables', []);
$table_header = [
t('Field'),
t('Type'),
t('Description'),
t('Apply anonymization'),
];
$db_schema = gdpr_get_complete_schema();
ksort($db_schema);
$more_header = [
t('Table name'),
t('Description'),
t('Columns'),
];
$form['more_wrapper'] = [
'#type' => 'fieldset',
'#title' => t('More tables'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'more_tables' => [
'#caption' => t("Select from the following tables to be able to configure more for anonymization, then press the 'Refresh form' button below to add them to the form."),
'#header' => $more_header,
'#type' => 'tableselect',
'#options' => [],
'#js_select' => FALSE,
],
'refresh' => [
'#type' => 'button',
'#value' => t('Refresh form'),
],
];
$added = [];
if (isset($form_state['values'])) {
$added = drupal_array_get_nested_value($form_state['values'], [
'more_wrapper',
'more_tables',
]);
$added = array_filter($added);
}
// Force some tables to always show in the form if they exist.
$forced = [
'comment' => TRUE,
'contact_message' => TRUE,
'users' => TRUE,
'webform_submission' => TRUE,
'webform_submitted_data' => TRUE,
];
foreach ($db_schema as $table => $table_schema) {
$table_comment = isset($table_schema['description']) ? $table_schema['description'] : NULL;
$table_configured = isset($mapping[$table]) || isset($empty_tables[$table]);
$table_forced = isset($forced[$table]);
$table_added = isset($added[$table]);
if ($table_configured || $table_added || $table_forced) {
$rows = [];
foreach ($table_schema['fields'] as $column_name => $column_info) {
$currentOptions = $sanitationOptions;
if (isset($mapping[$table][$column_name])) {
$currentOptions['#default_value'] = $mapping[$table][$column_name];
}
$rows[$column_name] = [
'name' => [
'#markup' => '<strong>' . $column_name . '</strong>',
],
'type' => [
'#markup' => '<strong>' . $column_info['type'] . '</strong>',
],
'description' => [
'#markup' => '<strong>' . (empty($column_info['description']) ? '-' : $column_info['description']) . '</strong>',
],
'option' => $currentOptions,
];
}
$form['tables'][$table] = [
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#title' => t('Table: %table', [
'%table' => $table,
]),
'#description' => $table_comment,
'empty_table' => [
'#type' => 'checkbox',
'#title' => t('Empty this table'),
'#default_value' => isset($empty_tables[$table]) ? $empty_tables[$table] : NULL,
'#weight' => 1,
],
'columns' => [
'#type' => 'container',
'#theme' => 'gdpr_dump_table_columns',
'#header' => $table_header,
'#weight' => 0,
] + $rows,
];
}
if (!$table_configured && !$table_forced) {
$row = [
[
'data' => [
'#markup' => '<strong>' . $table . '</strong>',
],
],
];
$row[] = $table_comment;
$row[] = implode(', ', array_keys($table_schema['fields']));
$form['more_wrapper']['more_tables']['#options'][$table] = $row;
}
}
$form['actions'] = [
'#type' => 'actions',
'save' => [
'#type' => 'submit',
'#value' => t('Save configuration'),
],
];
$form['more_wrapper']['#access'] = !empty($form['more_wrapper']['more_tables']['#options']);
return $form;
}