You are here

public function RedirectSource::onPreEntitySave in Acquia Content Hub 8.2

Adds the query parameter.

Parameters

\Drupal\acquia_contenthub\Event\PreEntitySaveEvent $event: The pre entity save event.

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

\Drupal\Core\Entity\EntityStorageException

File

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

Class

RedirectSource
Fixes the redirect source field to handle query parameters.

Namespace

Drupal\acquia_contenthub\EventSubscriber\PreEntitySave

Code

public function onPreEntitySave(PreEntitySaveEvent $event) {
  $entity = $event
    ->getEntity();

  // If it is not a redirect then exit.
  if ($entity
    ->getEntityTypeId() !== 'redirect') {
    return;
  }
  $data = json_decode(base64_decode($event
    ->getCdf()
    ->getMetadata()['data']), TRUE);
  $redirect_source = $data['redirect_source'];
  $this
    ->setQuery($redirect_source, $entity);
}