The advanced help topic nodes module generates its injection IDs like this:

// In hook_form_alter
  foreach ($form as $id=>$element) {
   $form[$id] = advanced_help_topic_nodes_for_forms_add_help_icons($id,$element,$form_id);
   $topic_id = $form_id . "--" . $id;
  }

The Help Inject does it like this:

function helpinject_get_helpkey($form_id, $form_element) {
  $clone = array('type' => $form_element['#type']);
  if (isset($form_element['#title'])) {
    $clone['title'] = $form_element['#title'];
  }
  $hash = md5(serialize($clone));
  return "{$form_id}-{$hash}";
}

The Help Inject's method is a bit subtler, perhaps to its detriment. It takes the #type and #title and MD5's them, plus a concatenation with the $form_id.

The FAPI is weird and diverse enough that I think I have to do an experiment to see how each of these approaches behave on different Drupal forms before I can make a decision.

Comments

robertdouglass’s picture

I did an experiment and have come up with this approach, which I'm implementing in the Help Inject module.

function x_form_alter(&$form, $form_state, $form_id) {
  x_step_form($form, $form_id, 'x_show');
}

function x_step_form(&$element, $form_id, $callback) {
  foreach (element_children($element) as $child) {
    x_step_form($element[$child], $form_id . ':' . $child, $callback);
  }
  $callback($element, $form_id);
}

function x_show($element, $form_id) {
  $types = array('checkbox','checkboxes','date','file','password','radio','radios','select','textarea','textfield');
  if (in_array($element['#type'], $types)) {
    dsm($form_id);
  }
}
robertdouglass’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.