You are here

public function Resource::getUrl in RESTful 7.2

Helper method; Get the URL of the resource and query strings.

By default the URL is absolute.

Parameters

array $options: Array with options passed to url().

bool $keep_query: If TRUE the $request will be appended to the $options['query']. This is the typical behavior for $_GET method, however it is not for $_POST. Defaults to TRUE.

RequestInterface $request: The request object.

Return value

string The URL address.

Overrides ResourceInterface::getUrl

File

src/Plugin/resource/Resource.php, line 512
Contains \Drupal\restful\Plugin\resource\Resource.

Class

Resource

Namespace

Drupal\restful\Plugin\resource

Code

public function getUrl(array $options = array(), $keep_query = TRUE, RequestInterface $request = NULL) {

  // By default set URL to be absolute.
  $options += array(
    'absolute' => TRUE,
    'query' => array(),
  );
  if ($keep_query) {
    $request = $request ?: $this
      ->getRequest();
    $input = $request
      ->getParsedInput();
    unset($input['page']);
    unset($input['range']);
    $input['page'] = $request
      ->getPagerInput();

    // Remove special params.
    unset($input['q']);

    // Add the request as query strings.
    $options['query'] += $input;
  }
  return $this
    ->versionedUrl($this
    ->getPath(), $options);
}