function _webform_validation_get_webform_element in Webform Validation 7
Get a reference to a specific webform element.
(For a given webform_validation rule component, and a given Drupal webform form, get a reference to the webform element represented by the rule component; return the correct element regardless of how deeply it's nested in webform fieldsets or other wrappers.)
Parameters
array $component: Webform validation rule component.
array $form: Drupal webform form.
Return value
array Reference to the webform element represented by the rule component.
1 call to _webform_validation_get_webform_element()
File
- ./
webform_validation.module, line 672
Code
function &_webform_validation_get_webform_element(array $component, array &$form) {
// Define an array of ancestors, beginning with the component itself.
$component_ancestors = array(
$component['form_key'],
);
// Define the parent-id, starting with the parent-id of the component itself,
// if any.
$pid = $component['pid'];
// Look into $form['#node']->webform['components'][$pid] to get any parent
// of the component, and continue working up the family tree until there is
// no more parent-id.
while ($pid) {
$parent = $form['#node']->webform['components'][$pid];
// Prepend the parent form_key to the array of ancestors. This causes the
// array of ancestors to be ordered from ancestor to descendant.
array_unshift($component_ancestors, $parent['form_key']);
// Note this parent's parent-id, if any.
$pid = $parent['pid'];
}
// $component_ancestors now contains the ordered ancestry. Cycle through it to
// get the correct member of $form['submitted']. Assign by reference so that
// we have a good reference to $webform_element to return.
$webform_element =& $form['submitted'];
foreach ($component_ancestors as $ancestor) {
$webform_element =& $webform_element[$ancestor];
}
return $webform_element;
}