You are here

public static function Helpers::getEndpointUrl in Search API Federated Solr 8.2

Same name and namespace in other branches
  1. 8.3 src/Utility/Helpers.php \Drupal\search_api_federated_solr\Utility\Helpers::getEndpointUrl()
  2. 4.x src/Utility/Helpers.php \Drupal\search_api_federated_solr\Utility\Helpers::getEndpointUrl()

Determines url to use for app search + autocomplete queries based on config:

  • defaults to absolute url to proxy route, appends qs params
  • if proxy disabled
    • compute and fallback to the server url
    • if direct url endpoint passed, use it

Parameters

integer $proxy_is_disabled: Flag indicating whether or not the autocomplete proxy is disabled (0 || 1)

string $direct_url: Value of the direct url ("" || <absolute-url-with-qs-params>)

string $qs: Querystring params to append to proxy url

Return value

string URL for the endpoint to be used for query requests.

2 calls to Helpers::getEndpointUrl()
FederatedSearchPageFormBlock::build in src/Plugin/Block/FederatedSearchPageFormBlock.php
Builds and returns the renderable array for this block plugin.
SearchController::content in src/Controller/SearchController.php
Returns content for a search page.

File

src/Utility/Helpers.php, line 69

Class

Helpers
Contains helper methods for the Search API Federated Solr module.

Namespace

Drupal\search_api_federated_solr\Utility

Code

public static function getEndpointUrl($proxy_is_disabled, $direct_url, $qs = '') {

  // Create proxy URL.
  $proxy_url_options = [
    'absolute' => TRUE,
  ];
  $proxy_link = Url::fromRoute('search_api_federated_solr.solr_proxy', [], $proxy_url_options);
  $proxy_url = $proxy_link
    ->toString();

  // Default to proxy url.
  $endpoint_url = $proxy_url;
  if ($proxy_is_disabled) {

    // Override with direct URL if provided.
    if ($direct_url) {
      $endpoint_url = $direct_url;
    }
    else {

      // Fallback to solr backend select handler URL.
      $endpoint_url = self::getSelectHandlerUrl();
    }
  }

  // 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;
  }
  return $endpoint_url;
}