Home

fQuery Sneak Preview

Sep 29, 2006

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...

Sep 29, 2006 Jeff Eaton

...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...

Oct 02, 2006 Nick Lewis

Reminds me of this very useful forms API function I jotted up a while ago. And yes, this function mass murders form elements.

<?php
function massmurder_elements(&$form, $element) {
    foreach (
element_children($form) as $key) {
        unset(
$form[$key][$element]);
    }
    return
$form;
}
?>

Post new comment

Note: all posts containing spam will be removed.
The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <b> <dd> <dl> <dt> <i> <li> <ol> <u> <ul> <img> <em> <p> <br> <span> <div> <h2> <h3> <abbr> <small> <table> <tr> <td> <strong> <acronym> <th> <blockquote>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options

Recent comments

Images