You can pass part of an array variable by reference in PHP5
Pretty nifty. PHP5 (and PHP4 for all I know) lets you pass not merely an entire variable, but part of a variable that is an array (and has nested arrays). Passing a variable by reference allows you to make changes directly to that variable in a function without having to figure out how to add those changes back-- the changes are made in the original variable, not in a copy (which is how variables passed to a function typically operate).
Example number one: $form['taxonomy']
<pre>
function wsf_action_form_alter($form_id, &$form) {
switch ($form_id) { // not $form['#id']
case 'profile_node_form':
$form['body_filter']['body']['#rows'] = 5;
wsf_action_fa_remove_taxonomy_fieldset($form['taxonomy']);
break;
...
}
}
</pre>
And here is the function that receives the taxonomy subset of the form array by reference:
<pre>
function wsf_action_fa_remove_taxonomy_fieldset(&$form_taxonomy) {
unset($form_taxonomy['#type']);
unset($form_taxonomy['#title']);
unset($form_taxonomy['#collapsible']);
unset($form_taxonomy['#collapsed']);
return;
}
No more annoying "Categories" title and collapsible fieldset if you don't want it!
Agaric tested and approved.
(Note to self: it might be advisable to put an if statement in there to check if there is a grouping of fields set before unsetting everything. Then again, maybe PHP is OK with the direct route.)
Comments
Post new comment