You are here

function variable_form_element in Variable 7

Same name and namespace in other branches
  1. 6 variable.form.inc \variable_form_element()
  2. 7.2 variable.form.inc \variable_form_element()

Build form element for a variable

3 calls to variable_form_element()
node_variable_type_subform in includes/node.variable.inc
Build subform for variables for node type
variable_edit_subform in ./variable.module
Form elements for variable list.
variable_form_element_multiple in ./variable.form.inc
Build multiple form element

File

./variable.form.inc, line 10
Variable API module. Form library.

Code

function variable_form_element($variable, $options = array()) {
  $variable = variable_build($variable);
  $variable = variable_build_options($variable, $options);
  if (!empty($variable['element callback'])) {
    $element = call_user_func($variable['element callback'], $variable, $options);
  }
  elseif (isset($variable['options'])) {
    $element = variable_form_element_options($variable, $options);
  }
  else {
    $element = variable_form_element_default($variable, $options);
  }
  if (!empty($variable['validate callback'])) {
    $element['#validate'][] = $variable['validate callback'];
  }
  if (!empty($options['form parents'])) {
    $element['#parents'] = $options['form parents'];
    $element['#parents'][] = $variable['name'];
  }
  $element += array(
    '#access' => variable_access($variable),
  );
  if (!empty($variable['required'])) {
    $element += array(
      '#required' => TRUE,
    );
  }
  return $element;
}