In drupal fapi there is an attribute “#process”.what exactly does it?Why password field use it for field duplication instead of adding it with theming?
I want to use it for defining a new field type with hook_elements.
Edit:
here is my hook_elements:
function test_elemets() {
return array(
'test_field' => array(
'#input' => TRUE,
'#process' => array('test_field_process'),
)
);
}
and process callback:
function test_field_process($element, $edit, &$form_state, $complete_form) {
$element = array();
return $element;
}
as you see in process function I used $element=array() to see what happens.But the form is shown as it was before.why?
Read the Forms API documentation on the ‘#process’ form element property.
It is an array of callback functions, each of which will be called with the the element definition array passed to it. The callback function can then act on the element definition array to turn it into a different (usually more complex) definition, like e.g. duplicating a password field while attaching an equality checking JavaScript file, or turning one combined ‘radios’ definition into an according amount of specific single ‘radio’ definitions, etc.
You will want to use it if you want to offer a complex form element (e.g. a combination of multiple ‘standard’ elements combined, or one with automatic addition of standard JavaScript helpers), but still keep the simple, declarative approach of the Forms API. (Look Ma – only one
'#type' = 'myCrazyFormElement'array, that expands ‘automagically’ to something way more complex 😉Doing this via the theming layer might be possible, depending on the use case, but would require more code, every time you need it.