You are here

public static function InsertView::build in Insert View 8

Same name and namespace in other branches
  1. 2.0.x src/Plugin/Filter/InsertView.php \Drupal\insert_view\Plugin\Filter\InsertView::build()

Parameters

$view_name:

$display_id:

$args:

Return value

array

File

src/Plugin/Filter/InsertView.php, line 61

Class

InsertView
Provides a filter for insert view.

Namespace

Drupal\insert_view\Plugin\Filter

Code

public static function build($view_name, $display_id, $args) {
  $plain = '';
  $view = Views::getView($view_name);
  if (empty($view)) {

    // Return renderable array.
    return [
      '#attached' => [],
      '#markup' => $plain,
    ];
  }
  if (!$view
    ->access($display_id)) {

    // Return renderable array.
    return [
      '#attached' => [],
      '#markup' => $plain,
    ];
  }
  $current_path = \Drupal::service('path.current')
    ->getPath();
  $url_args = explode('/', $current_path);
  foreach ($url_args as $id => $arg) {
    $args = str_replace("%{$id}", $arg, $args);
  }
  $args = preg_replace(',/?(%\\d),', '', $args);
  $args = $args ? explode('/', $args) : [];
  return $view
    ->preview($display_id, $args);
}