You are here

public function Redirect::setRedirect in Redirect 8

Sets the redirect destination URL data.

Parameters

string $url: The base url of the redirect destination.

array $query: Query arguments.

array $options: The source url options.

File

src/Entity/Redirect.php, line 207

Class

Redirect
The redirect entity class.

Namespace

Drupal\redirect\Entity

Code

public function setRedirect($url, array $query = [], array $options = []) {
  $uri = $url . ($query ? '?' . UrlHelper::buildQuery($query) : '');
  $external = UrlHelper::isValid($url, TRUE);
  $uri = $external ? $url : 'internal:/' . ltrim($uri, '/');
  $this->redirect_redirect
    ->set(0, [
    'uri' => $uri,
    'options' => $options,
  ]);
}