You are here

protected function RedirectSource::setQuery in Acquia Content Hub 8.2

Set query parameter for redirect.

Parameters

array $redirect_source: The redirect source.

\Drupal\redirect\Entity\Redirect $redirect: The redirect entity.

1 call to RedirectSource::setQuery()
RedirectSource::onPreEntitySave in src/EventSubscriber/PreEntitySave/RedirectSource.php
Adds the query parameter.

File

src/EventSubscriber/PreEntitySave/RedirectSource.php, line 57

Class

RedirectSource
Fixes the redirect source field to handle query parameters.

Namespace

Drupal\acquia_contenthub\EventSubscriber\PreEntitySave

Code

protected function setQuery(array $redirect_source, Redirect $redirect) {
  $langcode = $redirect
    ->getEntityType()
    ->getKey('langcode');
  $language = $redirect
    ->get($langcode)->value;
  $query = $redirect_source['value'][$language]['query'] ?? [];
  $path = $redirect
    ->getSource()['path'];
  if (!empty($query)) {
    $redirect
      ->setSource($path, $query);
  }
}