From 3721a6c5e6a6e429ffba8abf4757208f74beeb6c Mon Sep 17 00:00:00 2001 From: Dries Date: Sun, 9 Dec 2012 11:56:41 -0500 Subject: [PATCH] Issue #1861852 by dawehner, tim.plunkett: Fixed Views Attachments aren't rendered anymore. --- .../views/Plugin/views/display/Attachment.php | 9 ++- .../Tests/Plugin/DisplayAttachmentTest.php | 58 ++++++++++++++++ .../views/lib/Drupal/views/ViewExecutable.php | 12 ++-- .../views.view.test_display_attachment.yml | 67 +++++++++++++++++++ core/modules/views/theme/theme.inc | 14 +++- core/modules/views/theme/views-view.tpl.php | 4 +- 6 files changed, 149 insertions(+), 15 deletions(-) create mode 100644 core/modules/views/lib/Drupal/views/Tests/Plugin/DisplayAttachmentTest.php create mode 100644 core/modules/views/tests/views_test_config/test_views/views.view.test_display_attachment.yml diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/display/Attachment.php b/core/modules/views/lib/Drupal/views/Plugin/views/display/Attachment.php index 1e5e0e15680..cfd03a5ad4d 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/display/Attachment.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/display/Attachment.php @@ -254,18 +254,17 @@ class Attachment extends DisplayPluginBase { switch ($this->getOption('attachment_position')) { case 'before': - $this->view->attachment_before .= $attachment; + $this->view->attachment_before[] = $attachment; break; case 'after': - $this->view->attachment_after .= $attachment; + $this->view->attachment_after[] = $attachment; break; case 'both': - $this->view->attachment_before .= $attachment; - $this->view->attachment_after .= $attachment; + $this->view->attachment_before[] = $attachment; + $this->view->attachment_after[] = $attachment; break; } - $view->destroy(); } /** diff --git a/core/modules/views/lib/Drupal/views/Tests/Plugin/DisplayAttachmentTest.php b/core/modules/views/lib/Drupal/views/Tests/Plugin/DisplayAttachmentTest.php new file mode 100644 index 00000000000..3f21b88e615 --- /dev/null +++ b/core/modules/views/lib/Drupal/views/Tests/Plugin/DisplayAttachmentTest.php @@ -0,0 +1,58 @@ + 'Display: Attachment plugin', + 'description' => 'Tests the attachment display plugin.', + 'group' => 'Views Plugins', + ); + } + + protected function setUp() { + parent::setUp(); + + $this->enableViewsTestModule(); + } + + + /** + * Tests the attachment plugin. + */ + protected function testAttachment() { + // @todo Remove that once http://drupal.org/node/1828444 got in. + state()->set('menu_rebuild_needed', TRUE); + + $this->drupalGet('test-display-attachment'); + + $result = $this->xpath('//div[contains(@class, "view-content")]'); + $this->assertEqual(count($result), 2, 'Both actual view and the attachment is rendered.'); + + $result = $this->xpath('//div[contains(@class, "attachment-after")]'); + $this->assertEqual(count($result), 0, 'The attachment is not rendered after the actual view.'); + + $result = $this->xpath('//div[contains(@class, "attachment-before")]'); + $this->assertEqual(count($result), 1, 'The attachment is rendered before the actual view.'); + } + +} diff --git a/core/modules/views/lib/Drupal/views/ViewExecutable.php b/core/modules/views/lib/Drupal/views/ViewExecutable.php index f19b7db4a28..fdc4ce2ec7b 100644 --- a/core/modules/views/lib/Drupal/views/ViewExecutable.php +++ b/core/modules/views/lib/Drupal/views/ViewExecutable.php @@ -109,18 +109,18 @@ class ViewExecutable { public $total_rows = NULL; /** - * Rendered attachments to place before the view. + * Attachments to place before the view. * - * @var string + * @var array() */ - public $attachment_before = ''; + public $attachment_before = array(); /** - * Rendered attachements to place after the view. + * Attachments to place after the view. * - * @var string + * @var array */ - public $attachment_after = ''; + public $attachment_after = array(); // Exposed widget input diff --git a/core/modules/views/tests/views_test_config/test_views/views.view.test_display_attachment.yml b/core/modules/views/tests/views_test_config/test_views/views.view.test_display_attachment.yml new file mode 100644 index 00000000000..82a87fc2235 --- /dev/null +++ b/core/modules/views/tests/views_test_config/test_views/views.view.test_display_attachment.yml @@ -0,0 +1,67 @@ +api_version: '3.0' +base_field: id +base_table: views_test_data +core: 8.x +description: '' +disabled: '0' +display: + default: + display_plugin: default + id: default + display_title: Master + position: '' + display_options: + access: + type: perm + cache: + type: none + query: + type: views_query + exposed_form: + type: basic + pager: + type: full + options: + items_per_page: '10' + style: + type: default + row: + type: fields + fields: + name: + id: name + table: views_test_data + field: name + label: '' + alter: + alter_text: '0' + make_link: '0' + absolute: '0' + trim: '0' + word_boundary: '0' + ellipsis: '0' + strip_tags: '0' + html: '0' + hide_empty: '0' + empty_zero: '0' + link_to_node: '1' + title: test_display_attachment + page_1: + display_plugin: page + id: page_1 + display_title: Page + position: '1' + display_options: + path: test-display-attachment + attachment_1: + display_plugin: attachment + id: attachment_1 + display_title: Attachment + position: '2' + display_options: + displays: + page_1: page_1 +human_name: test_display_attachment +module: views +name: test_display_attachment +tag: '' diff --git a/core/modules/views/theme/theme.inc b/core/modules/views/theme/theme.inc index 48a78444604..dbdeb087299 100644 --- a/core/modules/views/theme/theme.inc +++ b/core/modules/views/theme/theme.inc @@ -92,8 +92,18 @@ function template_preprocess_views_view(&$vars) { $vars['pager'] = $view->renderPager($exposed_input); } - $vars['attachment_before'] = !empty($view->attachment_before) ? $view->attachment_before : ''; - $vars['attachment_after'] = !empty($view->attachment_after) ? $view->attachment_after : ''; + if (!empty($view->attachment_before)) { + $vars['attachment_before'] = $view->attachment_before; + } + else { + $vars['attachment_before'] = array(); + } + if (!empty($view->attachment_after)) { + $vars['attachment_after'] = $view->attachment_after; + } + else { + $vars['attachment_after'] = array(); + } // Add contextual links to the view. We need to attach them to the dummy // $view_array variable, since contextual_preprocess() requires that they be diff --git a/core/modules/views/theme/views-view.tpl.php b/core/modules/views/theme/views-view.tpl.php index 2bbb50738fc..05ce4c7b5b4 100644 --- a/core/modules/views/theme/views-view.tpl.php +++ b/core/modules/views/theme/views-view.tpl.php @@ -47,7 +47,7 @@
- +
@@ -67,7 +67,7 @@
- +