By Dan Silver on
In hook_form_alter() is there a way to hide all form elements, then specify which ones to display? Right now, I'm manually hiding them all, then showing them as needed.
Thanks!
function portfolio_form_alter(&$form, $form_state, $form_id) {
if (arg(0) == 'edit_portfolio_pages') {
hide($form['field_portfolio_settings']);
hide($form['field_portfolio_colors']);
hide($form['field_portfolio']);
hide($form['title']);
hide($form['additional_settings']);
$form['actions']['preview']['#access'] = FALSE;
$form['actions']['delete']['#access'] = FALSE;
}
if (drupal_get_path_alias() == "edit_portfolio_pages/" . arg(1) . "/content") {
show($form['field_portfolio']);
}
}
Comments
As I know, each key in form
As I know, each key in form array, which doesn't start with "#" is considered to be form element. You can create loop through $form array and set all items without '#'.
Calling the function
Calling the function element_children() and passing it the $form returns all the keys that don't begin with a # sign.
Contact me to contract me for D7 -> D10/11 migrations.
That's very good to know.
That's very good to know. Thanks!