I'm working on a module that needs to programatically remove a field from a view (both in the display and the query). The field needs to only be removed for their particular instance (ie: if they have two pages of the same view open and decide to remove a given field from one it should still be visible in the other page as well as any other users pages). Is this possible?
I have the form with select list made available in the header (since it's not really a filter I didn't want to simply create a filter handler -seemed confusing to users). I've supplied the current view using $view = views_get_current_view();
To remove the field I tried:
Use views_db_object::set_item with NULL item
<?php
$view->set_item('page_1','field','name_1', NULL);
?>Where name_1 is the id of the field I want to remove. It was suggested that passing a NULL item into this function would remove the field but on dpm of the views object after this command the field was still there and when the page finished refreshing due to form submit, the field was also still there.
Unset field object in all places I could find
<?php
unset(
$view->display['page_1']->handler->handlers['field']['name_1'],
$view->field['name_1']
);
?>When I dpm'd the views object directly after unset the field was gone wherever I expected it to be but on refresh of the page due to form submit, the field was still there even though it wasn't set in the views object. So apparently my modifactions are being kept when the view refreshes after the submit.
Thus I must simply be removing the field incorrectly. Maybe I've missed places the field object exists and should be unset? Or, hopefully, there is a better way altogether to do this...
Thanks for any help!
~Lacey