summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathaniel Catchpole2016-02-24 12:26:35 +0900
committerNathaniel Catchpole2016-02-24 12:26:35 +0900
commita975f31f8daa44b0c684d1a7bb53ac821e2a3114 (patch)
tree1b15f62fff7b84ed097b08d0311c840b6a45499b
parent6eb7091920413c697eb2d864b7960e5df1078e10 (diff)
Issue #2649352 by dawehner, borisson_: views_embed_view() should use a render array so metadata can bubble up
-rw-r--r--core/modules/views/src/Tests/ModuleTest.php18
-rw-r--r--core/modules/views/views.module11
2 files changed, 23 insertions, 6 deletions
diff --git a/core/modules/views/src/Tests/ModuleTest.php b/core/modules/views/src/Tests/ModuleTest.php
index f7eb9d7..0c7ff8b 100644
--- a/core/modules/views/src/Tests/ModuleTest.php
+++ b/core/modules/views/src/Tests/ModuleTest.php
@@ -275,20 +275,28 @@ class ModuleTest extends ViewKernelTestBase {
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);
}
/**
diff --git a/core/modules/views/views.module b/core/modules/views/views.module
index 0faa5bb..3122a74 100644
--- a/core/modules/views/views.module
+++ b/core/modules/views/views.module
@@ -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,
+ ];
}
/**