public static function InsertView::build in Insert View 2.0.x
Same name and namespace in other branches
- 8 src/Plugin/Filter/InsertView.php \Drupal\insert_view\Plugin\Filter\InsertView::build()
The parameters to tag syntax.
Parameters
mixed $view_name: The name of the view.
mixed $display_id: The display ID of the view.
mixed $args: An associative array of arguments.
string $limit: The limit to itens per page.
Return value
array A renderable array containing the view output
File
- src/
Plugin/ Filter/ InsertView.php, line 73
Class
- InsertView
- Provides a filter for insert view.
Namespace
Drupal\insert_view\Plugin\FilterCode
public static function build($view_name, $display_id, $args, $limit = '') {
$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) : [];
if (is_numeric($limit)) {
$view
->setItemsPerPage($limit);
}
return $view
->preview($display_id, $args);
}