You are here

public function ViewsReferenceArgument::alterView in Views Reference Field 8.2

Alter the view object.

Parameters

\Drupal\views\ViewExecutable $view: The view object to alter.

mixed $value: The field value.

Overrides ViewsReferenceSettingInterface::alterView

File

src/Plugin/ViewsReferenceSetting/ViewsReferenceArgument.php, line 33

Class

ViewsReferenceArgument
The views reference setting argument plugin.

Namespace

Drupal\viewsreference\Plugin\ViewsReferenceSetting

Code

public function alterView(ViewExecutable $view, $value) {
  if (!empty($value)) {
    $arguments = [
      $value,
    ];
    if (preg_match('/\\//', $value)) {
      $arguments = explode('/', $value);
    }
    $node = \Drupal::routeMatch()
      ->getParameter('node');
    $token_service = \Drupal::token();
    if (is_array($arguments)) {
      foreach ($arguments as $index => $argument) {
        if (!empty($token_service
          ->scan($argument))) {
          $arguments[$index] = $token_service
            ->replace($argument, [
            'node' => $node,
          ]);
        }
      }
    }
    $view
      ->setArguments($arguments);
  }
}