diff --git a/css/styles.css b/css/styles.css index fa6a270..2e8f4f5 100644 --- a/css/styles.css +++ b/css/styles.css @@ -32,3 +32,11 @@ text-decoration: none; cursor: pointer; } + +#pairs-wrapper .source-field, +#pairs-wrapper .destination-field { + max-width: 49%; + width: 49%; + box-sizing: border-box; + display: inline-block; /* keeps both at 49% inside a cell */ +} diff --git a/js/help_modal.js b/js/help_modal.js index c3d39bf..ebc5484 100644 --- a/js/help_modal.js +++ b/js/help_modal.js @@ -7,17 +7,15 @@ var modalContent = '
' . $this->t('Define the source and destination mappings.') . '
', @@ -53,26 +56,52 @@ final class RoblibAlterSolrSettingsForm extends ConfigFormBase { $form['pairs'] = [ '#type' => 'table', '#header' => [ + '', $this->t('Source'), $this->t('Destination'), $this->t('Operations'), + $this->t('Weight'), + ], + '#tabledrag' => [ + [ + 'action' => 'order', // we are ordering rows + 'relationship' => 'sibling', + 'group' => 'pairs-weight', // CSS class applied to the weight field + ], ], '#prefix' => '' . $this->t('Select aggregated field(s) to be normalized..') . '
', - ]; - $form['normalize'] = [ - '#type' => 'select', - '#multiple' => TRUE, - '#options' => $fields_options, - '#default_value' => $config->get('normalize') ?? '', - ]; + $form['#attached']['library'][] = 'roblib_alter_solr/roblib_alter_solr'; return parent::buildForm($form, $form_state); @@ -185,12 +216,15 @@ final class RoblibAlterSolrSettingsForm extends ConfigFormBase { */ public function submitForm(array &$form, FormStateInterface $form_state) { $pairs = $form_state->getValue('pairs'); + $filtered_pairs= array_filter($pairs, function ($item) { + return !empty($item['destination']); + }); $normalize = $form_state->getValue('normalize'); $this->config('roblib_alter_solr.settings') - ->set('pairs', $pairs) - ->set('normalize', $normalize) + ->set('pairs', $filtered_pairs) ->save(); - $this->messenger()->addStatus($this->t('Configuration saved successfully.')); + $this->messenger() + ->addStatus($this->t('Configuration saved successfully.')); } }