From b0aa1ae48cdfcb9c56c7690e434faeac0a082544 Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Tue, 11 Jun 2013 00:57:38 +0100 Subject: [PATCH] Issue #1888954 by dawehner: Attachments with only display cause a php error in the edit UI. --- .../views/Plugin/views/display/Attachment.php | 7 ++++--- .../views_ui/Tests/DisplayAttachmentTest.php | 16 ++++++++++++++-- 2 files changed, 18 insertions(+), 5 deletions(-) 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 99913840ec6..a36f4413d53 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 @@ -91,8 +91,8 @@ class Attachment extends DisplayPluginBase { } elseif (count($displays) == 1) { $display = array_shift($displays); - if (!empty($this->view->storage->display[$display])) { - $attach_to = check_plain($this->view->storage->display[$display]['display_title']); + if ($display = $this->view->storage->getDisplay($display)) { + $attach_to = check_plain($display['display_title']); } } @@ -217,12 +217,13 @@ class Attachment extends DisplayPluginBase { // It is very important to call the parent function here: parent::submitOptionsForm($form, $form_state); switch ($form_state['section']) { + case 'displays': + $form_state['values'][$form_state['section']] = array_filter($form_state['values'][$form_state['section']]); case 'inherit_arguments': case 'inherit_pager': case 'render_pager': case 'inherit_exposed_filters': case 'attachment_position': - case 'displays': $this->setOption($form_state['section'], $form_state['values'][$form_state['section']]); break; } diff --git a/core/modules/views_ui/lib/Drupal/views_ui/Tests/DisplayAttachmentTest.php b/core/modules/views_ui/lib/Drupal/views_ui/Tests/DisplayAttachmentTest.php index f4838f86ada..3c03f051e2b 100644 --- a/core/modules/views_ui/lib/Drupal/views_ui/Tests/DisplayAttachmentTest.php +++ b/core/modules/views_ui/lib/Drupal/views_ui/Tests/DisplayAttachmentTest.php @@ -36,14 +36,26 @@ class DisplayAttachmentTest extends UITestBase { $this->drupalGet('admin/structure/views/view/test_attachment_ui/edit/attachment_1'); $this->assertText(t('Not defined'), 'The right text appears if there is no attachment selection yet.'); - $this->drupalGet('admin/structure/views/nojs/display/test_attachment_ui/attachment_1/displays'); + $attachment_display_url = 'admin/structure/views/nojs/display/test_attachment_ui/attachment_1/displays'; + $this->drupalGet($attachment_display_url); foreach (array('default', 'page-1') as $display_id) { $this->assertNoFieldChecked("edit-displays-$display_id", format_string('Make sure the @display_id can be marked as attached', array('@display_id' => $display_id))); } // Save the attachments and test the value on the view. - $this->drupalPost(NULL, array('displays[default]' => 1, 'displays[page_1]' => 1), t('Apply')); + $this->drupalPost($attachment_display_url, array('displays[page_1]' => 1), t('Apply')); + $result = $this->xpath('//a[@id = :id]', array(':id' => 'views-attachment-1-displays')); + $this->assertEqual($result[0]->attributes()->title, t('Page')); + $this->drupalPost(NULL, array(), t('Save')); + + $view = views_get_view('test_attachment_ui'); + $view->initDisplay(); + $this->assertEqual(array_keys(array_filter($view->displayHandlers->get('attachment_1')->getOption('displays'))), array('page_1'), 'The attached displays got saved as expected'); + + $this->drupalPost($attachment_display_url, array('displays[default]' => 1, 'displays[page_1]' => 1), t('Apply')); + $result = $this->xpath('//a[@id = :id]', array(':id' => 'views-attachment-1-displays')); + $this->assertEqual($result[0]->attributes()->title, t('Multiple displays')); $this->drupalPost(NULL, array(), t('Save')); $view = views_get_view('test_attachment_ui');