You are here

function theme_fel_fields_socialfield_drag_components in Form element layout 7

Theme replacement for 'socialfield_drag_components' from socialfield.module.

File

modules/fel_fields/fel_fields.theme.inc, line 305
Theme replacement functions for Form element layout fields.

Code

function theme_fel_fields_socialfield_drag_components($vars) {
  $element = $vars['element'];
  drupal_add_tabledrag('socialfield-table', 'order', 'sibling', 'item-row-weight');
  $services = variable_get('socialfield_services');
  $header = array(
    t('Social links'),
    '',
    '',
    '',
  );
  $rows = array();
  $index = 0;
  for ($i = 0; $i < $element['#num_elements']; $i++) {
    while (!isset($element['element_' . $index])) {

      // There is no element with this index. Moving on to the next possible element.
      $index++;
    }
    $current_element = $element['element_' . $index];
    $rows[] = array(
      'data' => array(
        '<div class="social-links">' . '<span class="service-' . $current_element['#service'] . '">' . '<i class="icon ' . $services[$current_element['#service']]['icon'] . '"></i>' . '</span>' . '</div>',
        drupal_render($current_element['url']),
        drupal_render($current_element['weight']),
        drupal_render($current_element['operation']),
      ),
      'class' => array(
        'draggable',
      ),
      'weight' => $current_element['weight']['#value'],
    );
    $index++;
  }

  // Sorting elements by their weight.
  uasort($rows, 'drupal_sort_weight');
  $fel_items = array(
    'description' => isset($element['#description']) ? $element['#description'] : '',
    'children' => theme('table', array(
      'header' => $header,
      'rows' => $rows,
      'attributes' => array(
        'id' => 'socialfield-table',
      ),
    )) . drupal_render($element['add_one_social']),
  );
  return fel_order_output($element, $fel_items);
}