You are here

function name_element_expand in Name Field 7

Same name and namespace in other branches
  1. 8 name.module \name_element_expand()
  2. 6 name.module \name_element_expand()

The #process callback to create the element.

1 string reference to 'name_element_expand'
name_element_info in ./name.module
Implements hook_element_info().

File

./name.module, line 594
Defines an API for displaying and inputing names.

Code

function name_element_expand($element, &$form_state, $complete_form) {
  global $language;
  $element['#tree'] = TRUE;
  if (empty($element['#value'])) {
    $element['#value'] = array();
  }
  $parts = _name_translations();
  $element['#value'] += array_combine(array_keys($parts), array_fill(0, count($parts), ''));
  $components = $element['#components'];
  $min_components = (array) $element['#minimum_components'];
  if (empty($element['#field'])) {
    $element['#field'] = isset($form_state['field']) ? $form_state['field'] : NULL;
  }

  // Provides an override on the inline CSS.
  if (!empty($element['#component_css'])) {
    if ($element['#component_css'] == '<none>') {
      $inline_css = '';
    }
    else {
      $inline_css = ' style="' . check_plain($element['#component_css']) . '"';
    }
  }
  else {

    // Language will be LANGUAGE_LTR (0) or LANGUAGE_RTL (1).
    if ($language->direction) {
      if ($style = variable_get('name_inline_styles_rtl', 'float: right; margin-left: 1em;')) {
        $inline_css = ' style="' . $style . '"';
      }
    }
    else {
      if ($style = variable_get('name_inline_styles', 'float: left; margin-right: 1em;')) {
        $inline_css = ' style="' . $style . '"';
      }
    }
  }
  foreach ($parts as $key => $title) {
    if (!isset($components[$key]['exclude'])) {
      $element[$key] = _name_render_component($components, $key, $element, isset($min_components[$key]));
      $class = 'name-' . $key . '-wrapper';
      if ($key == 'credentials' && empty($element['#credentials_inline'])) {
        $element[$key]['#prefix'] = '<div class="' . $class . ' clearfix" style="float: ' . ($language->direction ? 'right' : 'left') . ';">';
        $element[$key]['#suffix'] = '</div>';
      }
      else {
        $element[$key]['#prefix'] = '<div class="' . $class . '"' . $inline_css . '>';
        $element[$key]['#suffix'] = '</div>';
      }
    }
  }
  if (variable_get('name_element_wrapper', 1)) {
    $element['#prefix'] = '<div class="clearfix">';
    $element['#suffix'] = '</div>';
  }
  return $element;
}