You are here

function field_group_pre_render_html_element in Field Group 7

Implements field_group_pre_render_<format-type>. Format type: HTML element.

Parameters

$element The field group form element.:

$group The Field group object prepared for pre_render.:

$form The root element or form.:

File

./field_group.module, line 717
Fieldgroup module.

Code

function field_group_pre_render_html_element(&$element, $group, &$form) {
  $html_element = isset($group->format_settings['instance_settings']['element']) ? $group->format_settings['instance_settings']['element'] : 'div';
  $show_label = isset($group->format_settings['instance_settings']['show_label']) ? $group->format_settings['instance_settings']['show_label'] : 0;
  $label_element = isset($group->format_settings['instance_settings']['label_element']) ? $group->format_settings['instance_settings']['label_element'] : 'div';
  $configured_attributes = isset($group->format_settings['instance_settings']['attributes']) ? ' ' . $group->format_settings['instance_settings']['attributes'] : '';
  $group->classes = trim($group->classes);

  // This regex split the attributes string so that we can pass that
  // later to drupal_attributes().
  preg_match_all('/([^\\s=]+)="([^"]+)"/', $configured_attributes, $matches);
  $element_attributes = array();

  // Put the attribute and the value together.
  foreach ($matches[1] as $key => $attribute) {
    $element_attributes[$attribute] = $matches[2][$key];
  }

  // Add the classes to the attributes array.
  if (!isset($element_attributes['class']) && $group->classes) {
    $element_attributes['class'] = $group->classes;
  }
  elseif (isset($element_attributes['class']) && $group->classes) {
    $element_attributes['class'] .= ' ' . $group->classes;
  }
  if (isset($element['#id'])) {
    $element_attributes['id'] = $element['#id'];
  }

  // Sanitize the attributes.
  $element_attributes = _filter_xss_attributes(drupal_attributes($element_attributes));
  $attributes = $element_attributes ? ' ' . implode(' ', $element_attributes) : '';
  $element['#prefix'] = '<' . $html_element . $attributes . '>';
  if ($show_label) {
    $element['#prefix'] .= '<' . $label_element . '><span>' . check_plain(t($group->label)) . '</span></' . $label_element . '>';
  }
  $element['#suffix'] = '</' . $html_element . '>';
}