Update: fQuery has been released.
Here's a sneak preview of something I've been working on since DrupalCon Brussels...
I've noticed that most hook_form_alter() uses need to look for certain elements in the $form array. For example, you want to make all resizable textareas fixed height. This means you have to iterate over $form and do recursion, find the matching elements and change them. That sucks.
What if you could just find all elements with certain properties with one line of code, and do stuff with them? Doesn't this sound at all familiar?
Enter: fQuery. In a hook_form_alter(), you could do:
<?php
$query = f('textarea.resizable', $form);
foreach ($query as &$element) {
$element['#resizable'] = FALSE;
}
?>Neat huh?

Also useful for node bodies...
...Now that we're storing them in similar structures in 5.0. When working on that patch, I considered whether something like this would be useful but realized it would be far more work than I had time to put into that patch.
This is very cool, I'm eager to see how it shapes up.
similar function...
Reminds me of this very useful forms API function I jotted up a while ago. And yes, this function mass murders form elements.
<?phpfunction massmurder_elements(&$form, $element) {
foreach (element_children($form) as $key) {
unset($form[$key][$element]);
}
return $form;
}
?>
Post new comment