Last active
September 15, 2021 01:41
-
-
Save infojunkie/c0195f034a5eaa420ad2 to your computer and use it in GitHub Desktop.
Debug info for Drupal forms
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name = Devel forms | |
description = Tools for developing and debugging Form API. | |
package = Development | |
core = 7.x | |
dependencies[] = devel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Implements hook_form_alter(). | |
*/ | |
function devel_forms_form_alter(&$form, &$form_state) { | |
$children = devel_forms_children($form); | |
foreach ($children as $key => &$child) { | |
$child['#attributes']['title'] = $key . ' => ' . print_r($child, TRUE); | |
} | |
} | |
function devel_forms_children(&$element) { | |
$results = array(); | |
foreach (element_children($element) as $key) { | |
$child = &$element[$key]; | |
if (is_array($child)) { | |
if (!empty($child['#type'])) { // OPTIONAL! | |
$results[$key] = &$child; | |
} | |
$results = array_merge($results, devel_forms_children($child)); | |
} | |
} | |
return $results; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment