|
|
|
|
@ -35,7 +35,7 @@ final class RoblibAlterSolrSettingsForm extends ConfigFormBase {
|
|
|
|
|
$solr_fields = $solr_config->get('field_settings'); |
|
|
|
|
$fields_options = []; |
|
|
|
|
foreach ($solr_fields as $name => $field) { |
|
|
|
|
$fields_options[$name] = $field['label']; |
|
|
|
|
$fields_options[$name] = $field['label'] . ' - ' . $name; |
|
|
|
|
} |
|
|
|
|
// Use getStorage() to persist state across AJAX calls. |
|
|
|
|
$pairs = $form_state->getStorage()['pairs'] ?? $form_state->get('pairs') ?? $config->get('pairs') ?? []; |
|
|
|
|
@ -46,6 +46,9 @@ final class RoblibAlterSolrSettingsForm extends ConfigFormBase {
|
|
|
|
|
'#prefix' => '<div id="open_link-wrapper">', |
|
|
|
|
'#suffix' => '</div>', |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$form['pairs_description'] = [ |
|
|
|
|
'#type' => 'markup', |
|
|
|
|
'#markup' => '<p><strong>' . $this->t('Define the source and destination mappings.') . '</strong></p>', |
|
|
|
|
@ -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' => '<div id="pairs-wrapper">', |
|
|
|
|
'#suffix' => '</div>', |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
$added = FALSE; |
|
|
|
|
|
|
|
|
|
foreach ($pairs as $index => $pair) { |
|
|
|
|
$form['pairs'][$index]['#attributes']['class'][] = 'draggable'; |
|
|
|
|
$form['pairs'][$index]['handle'] = [ |
|
|
|
|
'#markup' => '', |
|
|
|
|
'#attributes' => ['class' => ['tabledrag-handle']], |
|
|
|
|
]; |
|
|
|
|
$form['pairs'][$index]['source'] = [ |
|
|
|
|
'#type' => 'select', |
|
|
|
|
'#multiple' => TRUE, |
|
|
|
|
'#options' => $fields_options, |
|
|
|
|
'#default_value' => $pair['source'] ?? '', |
|
|
|
|
'#attributes' => ['class' => ['source-field']], |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
$form['pairs'][$index]['destination'] = [ |
|
|
|
|
'#type' => 'textfield', |
|
|
|
|
'#type' => 'select', |
|
|
|
|
'#options' => $fields_options, |
|
|
|
|
'#default_value' => $pair['destination'] ?? '', |
|
|
|
|
'#attributes' => ['class' => ['destination-field']], |
|
|
|
|
]; |
|
|
|
|
$form['pairs'][$index]['weight'] = [ |
|
|
|
|
'#type' => 'weight', |
|
|
|
|
'#title' => $this->t('Weight for row @row', ['@row' => $index]), |
|
|
|
|
'#title_display' => 'invisible', |
|
|
|
|
'#default_value' => $pair['weight'] ?? 0, |
|
|
|
|
'#attributes' => [ |
|
|
|
|
'class' => ['pairs-weight', 'tabledrag-hide'], |
|
|
|
|
], |
|
|
|
|
]; |
|
|
|
|
if ($pair['source'] && $pair['destination']) { |
|
|
|
|
$form['pairs'][$index]['remove'] = [ |
|
|
|
|
@ -101,25 +130,37 @@ final class RoblibAlterSolrSettingsForm extends ConfigFormBase {
|
|
|
|
|
$form['pairs'][$index]['destination']['#attributes'] = ['class' => ['destination-field']]; |
|
|
|
|
$added = TRUE; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
if (!$added) { |
|
|
|
|
$unique_id = uniqid(); |
|
|
|
|
$pairs[$unique_id] = ['source' => '', 'destination' => '']; |
|
|
|
|
$form['pairs'][$unique_id]['handle'] = [ |
|
|
|
|
'#markup' => '', |
|
|
|
|
'#attributes' => ['class' => ['tabledrag-handle']], |
|
|
|
|
]; |
|
|
|
|
$form['pairs'][$unique_id]['source'] = [ |
|
|
|
|
'#type' => 'select', |
|
|
|
|
'#multiple' => TRUE, |
|
|
|
|
'#options' => $fields_options, |
|
|
|
|
'#default_value' => '', |
|
|
|
|
'#default_value' => $pair['source'] ?? '', |
|
|
|
|
'#attributes' => ['class' => ['source-field']], |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
$form['pairs'][$unique_id]['destination'] = [ |
|
|
|
|
'#type' => 'textfield', |
|
|
|
|
'#type' => 'select', |
|
|
|
|
'#options' => $fields_options, |
|
|
|
|
'#default_value' => '', |
|
|
|
|
'#attributes' => ['class' => ['destination-field']], |
|
|
|
|
]; |
|
|
|
|
$form['add'] = [ |
|
|
|
|
$form['pairs'][$unique_id]['weight'] = [ |
|
|
|
|
'#type' => 'weight', |
|
|
|
|
'#title' => $this->t('Weight for row @row', ['@row' => $unique_id]), |
|
|
|
|
'#title_display' => 'invisible', |
|
|
|
|
'#default_value' => $pair['weight'] ?? 0, |
|
|
|
|
'#attributes' => [ |
|
|
|
|
'class' => ['pairs-weight', 'tabledrag-hide'], |
|
|
|
|
], |
|
|
|
|
]; |
|
|
|
|
$form['pairs'][$unique_id]['add'] = [ |
|
|
|
|
'#type' => 'submit', |
|
|
|
|
'#value' => $this->t('Add Row'), |
|
|
|
|
'#submit' => ['::addCallback'], |
|
|
|
|
@ -128,18 +169,8 @@ final class RoblibAlterSolrSettingsForm extends ConfigFormBase {
|
|
|
|
|
'wrapper' => 'pairs-wrapper', |
|
|
|
|
], |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
$form['normalize_description'] = [ |
|
|
|
|
'#type' => 'markup', |
|
|
|
|
'#markup' => '<p><strong>' . $this->t('Select aggregated field(s) to be normalized..') . '</strong></p>', |
|
|
|
|
]; |
|
|
|
|
$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.')); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|