Commit a975f31f authored by catch's avatar catch

Issue #2649352 by dawehner, borisson_: views_embed_view() should use a render...

Issue #2649352 by dawehner, borisson_: views_embed_view() should use a render array so metadata can bubble up
parent 6eb70919
......@@ -275,20 +275,28 @@ public function testViewsPluginList() {
public function testViewsEmbedView() {
$this->enableModules(array('user'));
/** @var \Drupal\Core\Render\RendererInterface $renderer */
$renderer = \Drupal::service('renderer');
$result = views_embed_view('test_argument');
$this->assertEqual(count($result['#view']->result), 5);
$renderer->renderPlain($result);
$this->assertEqual(count($result['view_build']['#view']->result), 5);
$result = views_embed_view('test_argument', 'default', 1);
$this->assertEqual(count($result['#view']->result), 1);
$renderer->renderPlain($result);
$this->assertEqual(count($result['view_build']['#view']->result), 1);
$result = views_embed_view('test_argument', 'default', '1,2');
$this->assertEqual(count($result['#view']->result), 2);
$renderer->renderPlain($result);
$this->assertEqual(count($result['view_build']['#view']->result), 2);
$result = views_embed_view('test_argument', 'default', '1,2', 'John');
$this->assertEqual(count($result['#view']->result), 1);
$renderer->renderPlain($result);
$this->assertEqual(count($result['view_build']['#view']->result), 1);
$result = views_embed_view('test_argument', 'default', '1,2', 'John,George');
$this->assertEqual(count($result['#view']->result), 2);
$renderer->renderPlain($result);
$this->assertEqual(count($result['view_build']['#view']->result), 2);
}
/**
......
......@@ -728,6 +728,10 @@ function _views_query_tag_alter_condition(AlterableInterface $query, &$condition
* valid. But things like 'page' or 'block' should work here.
* @param ...
* Any additional parameters will be passed as arguments.
*
* @return array|null
* A renderable array containing the view output or NULL if the display ID
* of the view to be executed doesn't exist.
*/
function views_embed_view($name, $display_id = 'default') {
$args = func_get_args();
......@@ -739,7 +743,12 @@ function views_embed_view($name, $display_id = 'default') {
return;
}
return $view->preview($display_id, $args);
return [
'#type' => 'view',
'#name' => $name,
'#display_id' => $display_id,
'#arguments' => $args,
];
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment