You are here

function theme_tracking_code_overview_table in Tracking Code 7

Theme function for the tracking code admin overview table.

Parameters

array $variables: an associative array of arguments (should only contain $form array)

Return value

array the admin overview form, themed as a draggable table of tracking_code

1 theme call to theme_tracking_code_overview_table()
tracking_code_overview_form in ./tracking_code.admin.inc
Form for tracking code overview table.

File

./tracking_code.admin.inc, line 32
admin page callbacks and form handlers for the tracking code module

Code

function theme_tracking_code_overview_table($variables) {
  global $base_url;
  $output = '';
  $form = $variables['form'];
  $regions = unserialize($form['regions']['#value']);
  if (empty($regions['header']) && empty($regions['page_top']) && empty($regions['page_bottom'])) {
    $link = l(t('Click here'), 'admin/structure/tracking_code/add');
    $output .= t('You have not configured any tracking code snippets. !link to add one.', array(
      '!link' => $link,
    ));
    return $output;
  }

  // Create a table for each region.
  foreach ($regions as $region => $snippets) {
    $rows = array();
    if (empty($snippets)) {

      // Nothing to do here...
      continue;
    }

    // Sort rows by weight before creating table.
    usort($snippets, '_tracking_code_weight_sort');

    // Build a row for each snippet.
    foreach ($snippets as $id => $snippet) {
      $actions = array();
      $enabled = $snippet->status ? t('Disable') : t('Enable');
      $query = array(
        'token' => drupal_get_token('disable_tc_snippet' . $snippet->tcid),
      ) + drupal_get_destination();
      $actions = array(
        l($enabled, 'admin/structure/tracking_code/disable/nojs/' . $snippet->tcid, array(
          'attributes' => array(
            'class' => array(
              'tracking-code-toggle-link',
              'use-ajax',
            ),
          ),
          'query' => $query,
        )),
        l(t('Configure'), 'admin/structure/tracking_code/' . $snippet->tcid . '/edit'),
        l(t('Delete'), 'admin/structure/tracking_code/' . $snippet->tcid . '/delete'),
      );
      $rows[] = array(
        'data' => array(
          array(
            'data' => check_plain($snippet->name),
            'class' => 'tracking-code-name',
          ),
          array(
            'data' => check_plain(truncate_utf8($snippet->code, 150, FALSE, '...')),
            'class' => 'tracking-code-code',
          ),
          implode(' | ', $actions),
          drupal_render($form['tracking_code'][$region]['weight_' . $snippet->tcid]),
        ),
        // Make all rows draggable.
        'class' => $snippet->status ? array(
          'draggable',
        ) : array(
          'draggable tracking-code-disabled',
        ),
        'id' => 'tcid-' . $snippet->tcid,
      );
    }
    switch ($region) {
      case 'header':
        $output .= '<h2>In &lt;HEAD&gt;</h2>';
        break;
      case 'page_top':
        $output .= '<h2>After &lt;BODY&gt;</h2>';
        break;
      case 'page_bottom':
        $output .= '<h2>Before &lt;/BODY&gt;</h2>';
        break;
    }
    $output .= theme('table', array(
      'header' => array(
        t('Name'),
        t('Code'),
        t('Actions'),
        t('Weight'),
      ),
      'rows' => $rows,
      'attributes' => array(
        'id' => 'tracking-code-admin-table-' . $region,
      ),
    ));
    drupal_add_tabledrag('tracking-code-admin-table-' . $region, 'order', 'siblings', 'snippet-weight');
  }
  $output .= drupal_render_children($form);
  return $output;
}