Issue #2389275 by bforchhammer: Views render element #embed not working
parent
14189a745f
commit
1c61006d90
|
@ -30,7 +30,7 @@ class View extends RenderElement {
|
|||
'#name' => NULL,
|
||||
'#display_id' => 'default',
|
||||
'#arguments' => array(),
|
||||
'#embed' => FALSE,
|
||||
'#embed' => TRUE,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,7 @@ class View extends RenderElement {
|
|||
}
|
||||
|
||||
if ($view && $view->access($element['#display_id'])) {
|
||||
if (!empty($element['embed'])) {
|
||||
if (!empty($element['#embed'])) {
|
||||
$element += $view->preview($element['#display_id'], $element['#arguments']);
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -21,7 +21,7 @@ class ViewElementTest extends ViewTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = array('test_view');
|
||||
public static $testViews = array('test_view_embed');
|
||||
|
||||
/**
|
||||
* The raw render data array to use in tests.
|
||||
|
@ -40,9 +40,10 @@ class ViewElementTest extends ViewTestBase {
|
|||
$this->render = array(
|
||||
'view' => array(
|
||||
'#type' => 'view',
|
||||
'#name' => 'test_view',
|
||||
'#name' => 'test_view_embed',
|
||||
'#display_id' => 'default',
|
||||
'#arguments' => array(25),
|
||||
'#embed' => FALSE,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -51,7 +52,7 @@ class ViewElementTest extends ViewTestBase {
|
|||
* Tests the rendered output and form output of a view element.
|
||||
*/
|
||||
public function testViewElement() {
|
||||
$view = Views::getView('test_view');
|
||||
$view = Views::getView('test_view_embed');
|
||||
$view->setDisplay();
|
||||
|
||||
// Set the content as our rendered array.
|
||||
|
@ -112,4 +113,72 @@ class ViewElementTest extends ViewTestBase {
|
|||
$this->assertEqual(count($xpath), 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the rendered output and form output of a view element, using the
|
||||
* embed display plugin.
|
||||
*/
|
||||
public function testViewElementEmbed() {
|
||||
$view = Views::getView('test_view_embed');
|
||||
$view->setDisplay('embed_1');
|
||||
|
||||
// Set the content as our rendered array.
|
||||
$render = $this->render;
|
||||
$render['#embed'] = TRUE;
|
||||
$this->drupalSetContent(drupal_render($render));
|
||||
|
||||
$xpath = $this->xpath('//div[@class="views-element-container"]');
|
||||
$this->assertTrue($xpath, 'The view container has been found in the rendered output.');
|
||||
|
||||
$xpath = $this->xpath('//div[@class="view-content"]');
|
||||
$this->assertTrue($xpath, 'The view content has been found in the rendered output.');
|
||||
// There should be 5 rows in the results.
|
||||
$xpath = $this->xpath('//div[@class="view-content"]/div');
|
||||
$this->assertEqual(count($xpath), 5);
|
||||
|
||||
// Test a form.
|
||||
$this->drupalGet('views_test_data_element_embed_form');
|
||||
|
||||
$xpath = $this->xpath('//div[@class="views-element-container form-wrapper"]');
|
||||
$this->assertTrue($xpath, 'The view container has been found on the form.');
|
||||
|
||||
$xpath = $this->xpath('//div[@class="view-content"]');
|
||||
$this->assertTrue($xpath, 'The view content has been found on the form.');
|
||||
// There should be 5 rows in the results.
|
||||
$xpath = $this->xpath('//div[@class="view-content"]/div');
|
||||
$this->assertEqual(count($xpath), 5);
|
||||
|
||||
// Add an argument and save the view.
|
||||
$view->displayHandlers->get('default')->overrideOption('arguments', array(
|
||||
'age' => array(
|
||||
'default_action' => 'ignore',
|
||||
'title' => '',
|
||||
'default_argument_type' => 'fixed',
|
||||
'validate' => array(
|
||||
'type' => 'none',
|
||||
'fail' => 'not found',
|
||||
),
|
||||
'break_phrase' => FALSE,
|
||||
'not' => FALSE,
|
||||
'id' => 'age',
|
||||
'table' => 'views_test_data',
|
||||
'field' => 'age',
|
||||
'plugin_id' => 'numeric',
|
||||
)
|
||||
));
|
||||
$view->save();
|
||||
|
||||
// Test the render array again.
|
||||
$render = $this->render;
|
||||
$render['#embed'] = TRUE;
|
||||
$this->drupalSetContent(drupal_render($render));
|
||||
// There should be 1 row in the results, 'John' arg 25.
|
||||
$xpath = $this->xpath('//div[@class="view-content"]/div');
|
||||
$this->assertEqual(count($xpath), 1);
|
||||
|
||||
// Test that the form has the same expected result.
|
||||
$this->drupalGet('views_test_data_element_embed_form');
|
||||
$xpath = $this->xpath('//div[@class="view-content"]/div');
|
||||
$this->assertEqual(count($xpath), 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
langcode: und
|
||||
status: true
|
||||
dependencies: { }
|
||||
id: test_view_embed
|
||||
label: 'Test view embed'
|
||||
module: views
|
||||
description: ''
|
||||
tag: ''
|
||||
base_table: views_test_data
|
||||
base_field: nid
|
||||
core: '8'
|
||||
display:
|
||||
default:
|
||||
display_options:
|
||||
defaults:
|
||||
fields: false
|
||||
pager: false
|
||||
sorts: false
|
||||
row:
|
||||
type: fields
|
||||
fields:
|
||||
age:
|
||||
field: age
|
||||
id: age
|
||||
relationship: none
|
||||
table: views_test_data
|
||||
plugin_id: numeric
|
||||
id:
|
||||
field: id
|
||||
id: id
|
||||
relationship: none
|
||||
table: views_test_data
|
||||
plugin_id: numeric
|
||||
name:
|
||||
field: name
|
||||
id: name
|
||||
relationship: none
|
||||
table: views_test_data
|
||||
plugin_id: string
|
||||
pager:
|
||||
options:
|
||||
offset: 0
|
||||
type: none
|
||||
sorts:
|
||||
id:
|
||||
field: id
|
||||
id: id
|
||||
order: ASC
|
||||
relationship: none
|
||||
table: views_test_data
|
||||
plugin_id: numeric
|
||||
field_langcode: '***LANGUAGE_language_content***'
|
||||
field_langcode_add_to_query: null
|
||||
display_plugin: default
|
||||
display_title: Master
|
||||
id: default
|
||||
position: 0
|
||||
embed_1:
|
||||
display_options: { }
|
||||
display_plugin: embed
|
||||
display_title: Embedded
|
||||
id: embed_1
|
||||
position: 1
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\views_test_data\Form\ViewsTestDataElementEmbedForm.
|
||||
*/
|
||||
|
||||
namespace Drupal\views_test_data\Form;
|
||||
|
||||
use Drupal\Core\Form\FormBase;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
* Simple form page callback to test the view element.
|
||||
*/
|
||||
class ViewsTestDataElementEmbedForm extends FormBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFormId() {
|
||||
return 'views_test_data_element_embed_form';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$form['view'] = array(
|
||||
'#type' => 'view',
|
||||
'#name' => 'test_view_embed',
|
||||
'#display_id' => 'embed_1',
|
||||
'#arguments' => array(25),
|
||||
'#embed' => TRUE,
|
||||
);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||
}
|
||||
}
|
|
@ -27,9 +27,10 @@ class ViewsTestDataElementForm extends FormBase {
|
|||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$form['view'] = array(
|
||||
'#type' => 'view',
|
||||
'#name' => 'test_view',
|
||||
'#name' => 'test_view_embed',
|
||||
'#display_id' => 'default',
|
||||
'#arguments' => array(25),
|
||||
'#embed' => FALSE,
|
||||
);
|
||||
|
||||
return $form;
|
||||
|
|
|
@ -4,3 +4,10 @@ views_test_data.element:
|
|||
_form: '\Drupal\views_test_data\Form\ViewsTestDataElementForm'
|
||||
requirements:
|
||||
_access: 'TRUE'
|
||||
|
||||
views_test_data.element_embed:
|
||||
path: '/views_test_data_element_embed_form'
|
||||
defaults:
|
||||
_form: '\Drupal\views_test_data\Form\ViewsTestDataElementEmbedForm'
|
||||
requirements:
|
||||
_access: 'TRUE'
|
||||
|
|
Loading…
Reference in New Issue