I've tested several Form API elements to see if hide() will successfully hide the elements in a hook_form_alter. It works nicely. I can't find any examples of core using this technique though. Is it a bad idea? Should contributed modules be sure to make their contributed form elements work with hide()?

I've seen much discussion about the best way to hide form elements (unset them, set ['#access'] = FALSE, hide them with CSS). Perhaps deciding whether hide() should be used on form elements in a form_alter context and then updating its documentation would be helpful.

See http://drupal.org/node/1419286 for a disagreement about whether hide() on contrib form elements should be supported.

Comments

jhodgdon’s picture

Category: task » support
Status: Active » Fixed

I think the documentation of hide() on api.drupal.org is clear enough, assuming that you realize that the set of "render elements" includes form elements.

You won't see one core module hiding other core module's form elements though. That would be a little wierd. It's more common in contrib/custom modules.

Anyway, I don't think there's documentation on api.drupal.org that needs fixing... so this is a support request?

mkadin’s picture

Status: Fixed » Closed (fixed)

Yup. Perhaps this was better set as a report request. I just wasn't sure if there was some sort of difference between form API renderable arrays and generic render arrays. I guess not.

Thanks for the clarification.