You are here

function field_group_pre_render_bootstrap_grid_row in Bootstrap fieldgroup 7

Implements field_group_pre_render_<format-type>. Format type: Bootstrap Grid Row.

Parameters

$element The field group form element.:

$group The Field group object prepared for pre_render.:

$form The root element or form.:

File

./bootstrap_fieldgroup.module, line 497
Module file for the bootstrap_fieldgroup module.

Code

function field_group_pre_render_bootstrap_grid_row(&$element, $group, &$form) {

  // Get the textual format of the the options available (xs, sm, md, lg).
  $screen_size_texts = _bootstrap_grid_col_screens();
  $settings = $group->format_settings['instance_settings'];

  // Add only the classes defined in the field group configuration. The rest
  // will be omitted.
  $col_classes = '';
  foreach ($screen_size_texts as $screen_size => $text) {
    if (!empty($settings['bootstrap_grid_col_' . $screen_size])) {
      $col_classes .= 'col-' . $screen_size . '-' . $settings['bootstrap_grid_col_' . $screen_size] . ' ';
    }
  }
  $prefix = '<div class="row ' . $group->classes . '">';
  $suffix = '</div>';

  // Wrap the fields in a panel if the panelize option is set to 1.
  // The panel needs to be wrapped in a column so that margins align correctly.
  if ($settings['panelize']) {
    $prefix .= '<div class="col-xs-12"><div class="panel panel-default"><div class="panel-body">';
    $suffix .= '</div></div></div>';
  }

  // If the show_heading configuration option is set to 1, add a column to
  // display the title and the description of the field group.
  if ($settings['show_heading']) {

    // If heading_position is 1, render the column after sub-groups so that it
    // shows on the right.
    if ($settings['heading_position']) {
      $suffix = '<div class="' . $col_classes . 'field-group-bootstrap_grid_row-heading">' . '<' . $settings['label_element'] . '>' . check_plain(t($group->label)) . '</' . $settings['label_element'] . '>' . '<' . $settings['description_element'] . '>' . $group->description . '</' . $settings['description_element'] . '>' . '</div>' . $suffix;
    }
    else {
      $prefix .= '<div class="' . $col_classes . 'field-group-bootstrap_grid_row-heading">' . '<' . $settings['label_element'] . '>' . check_plain(t($group->label)) . '</' . $settings['label_element'] . '>' . '<' . $settings['description_element'] . '>' . $group->description . '</' . $settings['description_element'] . '>' . '</div>';
    }
  }
  $element += array(
    '#type' => 'markup',
    '#prefix' => $prefix,
    '#suffix' => $suffix,
  );
}