hook_elements

Versions
4.7 – 6
hook_elements()

Allows modules to declare their own Forms API element types and specify their default values.

This hook allows modules to declare their own form element types and to specify their default values. The values returned by this hook will be merged with the elements returned by hook_form() implementations and so can return defaults for any Form APIs keys in addition to those explicitly mentioned below.

Each of the form element types defined by this hook is assumed to have a matching theme function, e.g. theme_elementtype(), which should be registered with hook_theme() as normal.

Form more information about custom element types see the explanation at http://drupal.org/node/169815 .

Return value

An associative array describing the element types being defined. The array contains a sub-array for each element type, with the machine-readable type name as the key. Each sub-array has a number of possible attributes:

  • "#input": boolean indicating whether or not this element carries a value (even if it's hidden).
  • "#process": array of callback functions taking $element, $edit, $form_state, and $complete_form.
  • "#after_build": array of callback functions taking $element and $form_state.
  • "#validate": array of callback functions taking $form and $form_state.
  • "#element_validate": array of callback functions taking $element and $form_state.
  • "#pre_render": array of callback functions taking $element and $form_state.
  • "#post_render": array of callback functions taking $element and $form_state.
  • "#submit": array of callback functions taking $form and $form_state.

Related topics

Code

developer/hooks/core.php, line 450

<?php
function hook_elements() {
  $type['filter_format'] = array('#input' => TRUE);
  return $type;
}
?>

Remember to theme

mikl - Tue, 2009-08-25 09:03

Remember that if you create your own element, you will need to provide a theme callback for it, at minimum something like this:

<?php
function theme_myfancyelement($element) {
  return
$element['#children'];
}
?>

Also, remember to register your theming function with hook_theme().

Using drupal_render()

mavimo - Thu, 2009-10-29 18:46

When you theme your element please don't return element, but:

<?php
return drupal_render($element);
?>

Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.