Help Text for Link Field Columns
The Link module is the gold standard for adding link fields to a Drupal site. Here’s what the link field looks like with the default help text:
I wanted to add some helpful text under the “URL” [sub]field. First, I tried setting the “Help text” in the field’s settings:
That isn’t quite what I was looking for. I needed to move that help text directly below the “URL” [sub]field. Looking at where the Title [sub]field help text is set (thanks to grep), I was able to determine which alter hook I ought to be using. hook_element_info_alter() is what I ended up using. Here’s how:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
/** * Implements hook_element_info_alter(). */ function mymodule_element_info_alter(&$elements) { if (isset($elements['link_field'])) { $elements['link_field']['#process'][] = 'mymodule_link_field_process'; } } /** * Process callback for the link_field field. */ function mymodule_link_field_process($element, $form_state, $complete_form) { // Add help text under the "url" column of the link widget $element['url']['#description'] = t('<strong>Internal:</strong> <em>node/#</em> <strong>External:</strong> <em>full url</em> <strong>Email:</strong> <em>mailto:emailaddress</em>'); return $element; } |
And here’s the result: