Issue #1786540 by damiankloip: Added a ViewExecutable::removeItem method.

8.0.x
webchick 2013-01-09 11:59:17 -08:00
parent d9a727416e
commit 143994ccf0
4 changed files with 35 additions and 8 deletions

View File

@ -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',

View File

@ -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);
}
/**

View File

@ -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);

View File

@ -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']);