Skip to content

Instantly share code, notes, and snippets.

@infojunkie
Last active September 15, 2021 01:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save infojunkie/c0195f034a5eaa420ad2 to your computer and use it in GitHub Desktop.
Save infojunkie/c0195f034a5eaa420ad2 to your computer and use it in GitHub Desktop.
Debug info for Drupal forms
name = Devel forms
description = Tools for developing and debugging Form API.
package = Development
core = 7.x
dependencies[] = devel
<?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