You are here

public function LoadMatchingRedirect::onLoadLocalEntity in Acquia Content Hub 8.2

Loads local matching redirects to avoid duplicate redirect errors.

Parameters

\Drupal\acquia_contenthub\Event\LoadLocalEntityEvent $event: The local entity loading event.

Throws

\Exception

File

modules/acquia_contenthub_subscriber/src/EventSubscriber/LoadLocalEntity/LoadMatchingRedirect.php, line 37

Class

LoadMatchingRedirect
Class LoadMatchingRedirect.

Namespace

Drupal\acquia_contenthub_subscriber\EventSubscriber\LoadLocalEntity

Code

public function onLoadLocalEntity(LoadLocalEntityEvent $event) {
  $cdf = $event
    ->getCdf();
  if (!$this
    ->isSupported($cdf)) {
    return;
  }
  $data = json_decode(base64_decode($cdf
    ->getMetadata()['data']), TRUE);
  $redirect_source = $data['redirect_source'];
  $langcode = $cdf
    ->getMetadata()['default_language'];
  $redirect = $this
    ->getExistingRedirect($redirect_source, $langcode);
  if ($redirect) {
    $event
      ->setEntity($redirect);
    $event
      ->stopPropagation();
  }
}