diff --git a/js/help_modal.js b/js/help_modal.js index ecb6259..8333e42 100644 --- a/js/help_modal.js +++ b/js/help_modal.js @@ -8,10 +8,15 @@ var modalContent = '<div id="help-modal" class="modal">' + '<div class="modal-content">' + '<span class="close-button">×</span>' + - '<h2>Roblib Solr Alter</h2>' + - '<p>The form allows you two or more existing Solr fields to a new multivalues field.</p>' + - '<p>Select existing fields from the dropdowns on the left, and pair them with a new field</ br> '+ - 'in the column on the right. Your new field name comply with your Solr installion\'s schema.</p>' + + '<h3>Consolidating existing Solr fields</h3>' + + '<p>The form allows you concatenate two or more existing Solr fields to a new multivalue field. </ br>' + + 'Select existing fields from the dropdowns on the left, to pair them with a new field</ br> '+ + 'entered in the column on the right. </ br>The new field name need not exist in your Solr config already.</p>' + + '<h3>Normalizing Custom Strings</h3>' + + '<p>Create a Custom value string on your Solr index, and populate it with pipe separated tokens ' + + 'such as <em>[node:field_country]|[node:field_geo_area]|node:field_geo_city]</em>, ' + + 'then select this field in the Normalize selector below. The resulting Solr field will be a comma-separated string, ' + + 'allowing multiple values per tokenized Drupal field. </p>' '</div>' + '</div>'; @@ -21,10 +26,12 @@ // Show the modal $('#help-modal').fadeIn(); + $("#open_link-wrapper").fadeOut(); // Close the modal when clicking the close button $('#help-modal .close-button').click(function () { $('#help-modal').fadeOut(function () { + $("#open_link-wrapper").fadeIn(); $('#help-modal').remove(); // Remove modal from DOM after closing }); }); @@ -32,6 +39,7 @@ // Close the modal when clicking outside the modal content $(window).click(function(event) { if ($(event.target).is('#help-modal')) { + $("#open_link-wrapper").fadeIn(); $('#help-modal').fadeOut(function () { $('#help-modal').remove(); // Remove modal from DOM }); diff --git a/js/roblib_alter_solr.js b/js/roblib_alter_solr.js index d4e6073..874dfd1 100644 --- a/js/roblib_alter_solr.js +++ b/js/roblib_alter_solr.js @@ -10,7 +10,7 @@ var sourceFilled = sourceField.find('option:selected').length > 0; var destinationFilled = destinationField.val().trim().length > 0; // Show/hide button based on whether both fields are filled - if (sourceFilled && destinationFilled) { + if (sourceFilled) { $('.form-submit[value="Add Row"]', context).show(); } else { $('.form-submit[value="Add Row"]', context).hide(); diff --git a/src/EventSubscriber/RoblibAlterSolrSubscriber.php b/src/EventSubscriber/RoblibAlterSolrSubscriber.php index 94af3e1..9e6acea 100644 --- a/src/EventSubscriber/RoblibAlterSolrSubscriber.php +++ b/src/EventSubscriber/RoblibAlterSolrSubscriber.php @@ -73,6 +73,21 @@ final class RoblibAlterSolrSubscriber implements EventSubscriberInterface { $field_name = "sm_{$values['destination']}"; $solrDocument->setField($field_name, $consolidated_values); } + foreach ($this->config->get('normalize') as $name) { + $field_value = $item->getField($name); + if ($field_value && $field_value->getValues()) { + $value = $field_value->getValues()[0] ?? ''; + $cleaned_string = preg_match('/^\|+$/', $value) ? '' : preg_replace('/\|+/', ', ', $value); + if ($cleaned_string) { + $solrDocument->setField("ss_{$name}", $cleaned_string); + } + else { + $solrDocument->removeField("ss_{$name}"); + } + + } + } + } } diff --git a/src/Form/RoblibAlterSolrSettingsForm.php b/src/Form/RoblibAlterSolrSettingsForm.php index 4f458de..d0db28e 100644 --- a/src/Form/RoblibAlterSolrSettingsForm.php +++ b/src/Form/RoblibAlterSolrSettingsForm.php @@ -46,7 +46,10 @@ 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>', + ]; $form['pairs'] = [ '#type' => 'table', '#header' => [ @@ -127,6 +130,16 @@ final class RoblibAlterSolrSettingsForm extends ConfigFormBase { ]; } + $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); @@ -172,12 +185,12 @@ final class RoblibAlterSolrSettingsForm extends ConfigFormBase { */ public function submitForm(array &$form, FormStateInterface $form_state) { $pairs = $form_state->getValue('pairs'); - $config = $this->config('roblib_alter_solr.settings'); - $config->set('pairs', $pairs)->save(); - + $normalize = $form_state->getValue('normalize'); + $this->config('roblib_alter_solr.settings') + ->set('pairs', $pairs) + ->set('normalize', $normalize) + ->save(); $this->messenger()->addStatus($this->t('Configuration saved successfully.')); } - - }