diff --git a/core/modules/comment/lib/Drupal/comment/Tests/Views/FilterUserUIDTest.php b/core/modules/comment/lib/Drupal/comment/Tests/Views/FilterUserUIDTest.php index 514ceb372b5..51de3815259 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/Views/FilterUserUIDTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/Views/FilterUserUIDTest.php @@ -32,7 +32,7 @@ class FilterUserUIDTest extends CommentTestBase { function testCommentUserUIDTest() { $view = views_get_view('test_comment_user_uid'); $view->setDisplay(); - $view->setItem('default', 'argument', 'uid_touch', NULL); + $view->removeItem('default', 'argument', 'uid_touch'); $options = array( 'id' => 'uid_touch', diff --git a/core/modules/views/lib/Drupal/views/Tests/ViewStorageTest.php b/core/modules/views/lib/Drupal/views/Tests/ViewStorageTest.php index 4bfad2cd1ca..57a6f85fccc 100644 --- a/core/modules/views/lib/Drupal/views/Tests/ViewStorageTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/ViewStorageTest.php @@ -381,6 +381,11 @@ class ViewStorageTest extends ViewTestBase { $view->setItem($display_id, 'field', $id1, $item); $this->assertEqual($view->getItem($display_id, 'field', 'id'), $item); $this->assertEqual($view->getItems('field', $display_id), $expected_items); + + // Test removeItem method. + unset($expected_items[$id2]); + $view->removeItem($display_id, 'field', $id2); + $this->assertEqual($view->getItems('field', $display_id), $expected_items); } /** diff --git a/core/modules/views/lib/Drupal/views/ViewExecutable.php b/core/modules/views/lib/Drupal/views/ViewExecutable.php index 0c22e3b0e49..d538b09e6de 100644 --- a/core/modules/views/lib/Drupal/views/ViewExecutable.php +++ b/core/modules/views/lib/Drupal/views/ViewExecutable.php @@ -2076,7 +2076,7 @@ class ViewExecutable { } // Get info about the types so we can get the right data. - $types = $this::viewsHandlerTypes(); + $types = static::viewsHandlerTypes(); return $this->displayHandlers[$display_id]->getOption($types[$type]['plural']); } @@ -2096,7 +2096,7 @@ class ViewExecutable { */ public function getItem($display_id, $type, $id) { // Get info about the types so we can get the right data. - $types = $this::viewsHandlerTypes(); + $types = static::viewsHandlerTypes(); // Initialize the display $this->setDisplay($display_id); @@ -2131,7 +2131,7 @@ class ViewExecutable { */ public function setItem($display_id, $type, $id, $item) { // Get info about the types so we can get the right data. - $types = $this::viewsHandlerTypes(); + $types = static::viewsHandlerTypes(); // Initialize the display. $this->setDisplay($display_id); @@ -2140,9 +2140,31 @@ class ViewExecutable { if (isset($item)) { $fields[$id] = $item; } - else { - unset($fields[$id]); - } + + // Store. + $this->displayHandlers[$display_id]->setOption($types[$type]['plural'], $fields); + } + + /** + * Removes configuration for a handler instance on a given display. + * + * @param string $display_id + * The machine name of the display. + * @param string $type + * The type of handler being removed. + * @param string $id + * The ID of the handler being removed. + */ + public function removeItem($display_id, $type, $id) { + // Get info about the types so we can get the right data. + $types = static::viewsHandlerTypes(); + // Initialize the display. + $this->setDisplay($display_id); + + // Get the existing configuration. + $fields = $this->displayHandlers[$display_id]->getOption($types[$type]['plural']); + // Unset the item. + unset($fields[$id]); // Store. $this->displayHandlers[$display_id]->setOption($types[$type]['plural'], $fields); diff --git a/core/modules/views/views_ui/admin.inc b/core/modules/views/views_ui/admin.inc index ceb650b3528..09fedbef4bc 100644 --- a/core/modules/views/views_ui/admin.inc +++ b/core/modules/views/views_ui/admin.inc @@ -1711,7 +1711,7 @@ function views_ui_config_item_form_remove($form, &$form_state) { $display =& $form_state['view']->get('executable')->displayHandlers[$form_state['display_id']]; $display->optionsOverride($form, $form_state); } - $form_state['view']->get('executable')->setItem($form_state['display_id'], $form_state['type'], $form_state['id'], NULL); + $form_state['view']->get('executable')->removeItem($form_state['display_id'], $form_state['type'], $form_state['id']); // Write to cache views_ui_cache_set($form_state['view']);