It’s kind of update of function: unsetAllExcept. Lately I had a problem with unsetting some default widgets. Using for example propel and relations m-n, auto-generated forms have widgets that cannot be unsets using the current version of function - it only unset widgets by form object fields.
I think it could be useful:
<?php
/**
* unset all fields except given parameters
*
* @param array $fields Array of fields
*/
public function unsetAllExcept($fields = array())
{
$tmp = array_keys($this->widgetSchema->getFields());
foreach(array_diff($tmp, $fields) as $value){
unset($this[$value]);
}
}
?>
Hidden fields can’t be removed because they are beeing used in CRUD actions and maybe also in other actions.
Use this instead:
[code]
public function useFields($fields)
{
foreach ($this->getWidgetSchema()->getFields() as $name => $widget)
{
if (!in_array($name, $fields) && !$widget->isHidden())
{
unset($this[$name]);
}
}
}
[/code]