Skip to content

Commit

Permalink
Merge branch '3045930-use-canonical-urls' into 8.x-2.2-integration
Browse files Browse the repository at this point in the history
  • Loading branch information
jesconstantine committed Apr 4, 2019
2 parents 2949ce3 + c073eb5 commit d8903b7
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 9 deletions.
3 changes: 3 additions & 0 deletions css/main.ec684809.css

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions css/main.ec684809.css.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions js/main.6dd42607.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions js/main.6dd42607.js.map

Large diffs are not rendered by default.

24 changes: 23 additions & 1 deletion js/search_api_federated_solr_autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,32 @@
return "<strong>" + string + "</strong>"
});

// Default the URL to the passed ss_url.
let href = item.ss_url;

// Ensure that the result returned for the item from solr
// (via proxy or directly) is assigned an absolute URL.
if (!options.directUrl) {
// Initialize url to compute from solr sm_urls array.
let sm_url;
// Use the canonical url.
if (Array.isArray(item.sm_urls)) {
sm_url = item.sm_urls[0];
}

// If no valid urls are passed from solr, skip this item.
if (!sm_url) {
return;
}

// Override the current href value.
href = sm_url;
}

//Add results to the list
var $suggestionTemplate = `
<div role='option' tabindex='-1' class='js-autocomplete-suggestion autocomplete-suggestion' id='suggestion-${counter}'>
<a class='js-autocomplete-suggestion__link autocomplete-suggestion__link' href='${item.ss_url}'>${highlighted}</a>
<a class='js-autocomplete-suggestion__link autocomplete-suggestion__link' href='${href}'>${highlighted}</a>
<span class='visually-hidden'>(${counter} of ${limitedResults.length})</span>
</div>`;
$results.append($suggestionTemplate);
Expand Down
11 changes: 8 additions & 3 deletions search_api_federated_solr.libraries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@ search:
version: 2.x
css:
theme:
https://cdn.jsdelivr.net/gh/palantirnet/[email protected]/css/main.ec684809.css:
type: external
# https://cdn.jsdelivr.net/gh/palantirnet/[email protected]/css/main.ec684809.css:
# type: external
# minified: true
css/main.ec684809.css:
minified: true
js:
https://cdn.jsdelivr.net/gh/palantirnet/[email protected]/js/main.41ba8df2.js:
# https://cdn.jsdelivr.net/gh/palantirnet/[email protected]/js/main.41ba8df2.js:
# preprocess: false
# minified: true
js/main.6dd42607.js:
preprocess: false
minified: true

Expand Down
3 changes: 1 addition & 2 deletions src/Form/SearchApiFederatedSolrSearchAppSettingsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -696,11 +696,10 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
// If enabled, set the autocomplete options.
if ($autocomplete_is_enabled) {
// Cache form values that we'll use more than once.
$autocomplete_direct_url = $form_state->getValue('autocomplete_direct_url');
$autocomplete_mode = $form_state->getValue('autocomplete_mode');

// Determine the url to be used for autocomplete queries based on proxy flag.
$proxy_is_disabled = $form_state->getValue('autocomplete_disable_query_proxy');
$autocomplete_direct_url = $proxy_is_disabled ? $form_state->getValue('autocomplete_direct_url') : '';

// Default to the form values
$autocomplete_username = $form_state->getValue('autocomplete_username');
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin/Block/FederatedSearchPageFormBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ public function blockSubmit($form, FormStateInterface $form_state) {
// Set the actual autocomplete config options.
$autocomplete['isEnabled'] = $autocomplete_is_enabled;
$autocomplete['proxyIsDisabled'] = $values['autocomplete']['disable_query_proxy'];
$autocomplete['directUrl'] = $values['autocomplete']['direct']['autocomplete_url'];
$autocomplete['directUrl'] = $autocomplete['proxyIsDisabled'] ? $values['autocomplete']['direct']['autocomplete_url'] : '';
$autocomplete['use_search_app_creds'] = $use_search_app_creds;

if ($username) {
Expand Down
5 changes: 3 additions & 2 deletions src/Utility/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ public static function getEndpointUrl($proxy_is_disabled, $direct_url, $qs = '')
}
}

// Append qs params for block form autocomplete js.
if ($qs) {
// Append qs params for block form autocomplete js unless configured
// with a direct url (like a view rest export endpoint).
if ($qs && !$direct_url) {
$endpoint_url .= $qs;
}

Expand Down

0 comments on commit d8903b7

Please sign in to comment.