You are here

function theme_feeds_tamper_ui_list_form in Feeds Tamper 7

Same name and namespace in other branches
  1. 6 feeds_tamper_ui/feeds_tamper_ui.admin.inc \theme_feeds_tamper_ui_list_form()

Theme callback for plugin list tables.

File

feeds_tamper_ui/feeds_tamper_ui.admin.inc, line 180
Forms and their accompanying validation and submit functions for Feeds Tamper UI.

Code

function theme_feeds_tamper_ui_list_form($variables) {
  $form = $variables['form'];

  // Shortcut to save typing and screen space.
  if (empty($form['mappings'])) {
    return;
  }
  $map =& $form['mappings'];
  $mappings = element_children($map);
  $header_normal = array(
    t('Description'),
    t('Weight'),
    t('Plugin'),
    t('Status'),
    t('Operations'),
    t('Enabled'),
  );

  // Remove weight column for empty tables. It looks nicer.
  $header_empty = $header_normal;
  unset($header_empty[1]);
  foreach ($mappings as $key => $i) {
    $table_rows = $disabled_rows = array();

    // We used to use the source name in the table id, but it just needs to be
    // unique, so use the key to avoid problems.
    $table_id = 'feeds-tamper-' . $key . '-table';

    // Plugin instances for a particluar source.
    $instances = element_children($map[$i]['table']);
    if (empty($instances)) {
      $header = $header_empty;
      $help_text = t('No plugins defined.');
      $table_rows = array(
        'data' => array(
          array(
            'data' => $help_text,
            'colspan' => 5,
          ),
        ),
      );
    }
    else {
      $header = $header_normal;
      foreach ($instances as $id) {
        $enabled = !empty($map[$i]['table'][$id]['enabled']['#default_value']);

        // Assemble enabled plugin rows.
        if ($enabled) {
          $this_row = array();

          // Add description column.
          $this_row[] = $map[$i]['table'][$id]['#description'];

          // Add weight column, it will be hidden if javascript is enabled.
          $this_row[] = drupal_render($map[$i]['table'][$id]['weight']);

          // The name of the plugin, as defined in a PLUGIN.inc.
          $this_row[] = $map[$i]['table'][$id]['#name'];

          // One of Normal, Default, Overridden.
          $this_row[] = $map[$i]['table'][$id]['#status'];

          // Operations to perform on a plugin instance.
          $this_row[] = $map[$i]['table'][$id]['#edit'];

          // Enabled checkbox.
          $this_row[] = drupal_render($map[$i]['table'][$id]['enabled']);

          // Add draggable class for sortable table.
          $table_rows[] = array(
            'data' => $this_row,
            'class' => array(
              'draggable',
            ),
          );
        }
        else {

          // Assemble disabled plugin rows.
          $this_row = array();

          // Add description column.
          $this_row[] = $map[$i]['table'][$id]['#description'];

          // Add weight column, it will be hidden if javascript is enabled.
          $this_row[] = drupal_render($map[$i]['table'][$id]['weight']);

          // The name of the plugin, as defined in a PLUGIN.inc.
          $this_row[] = $map[$i]['table'][$id]['#name'];

          // One of Normal, Default, Overridden.
          $this_row[] = $map[$i]['table'][$id]['#status'];

          // Operations to perform on a plugin instance. It's disabled, so make
          // it just text.
          $this_row[] = strip_tags($map[$i]['table'][$id]['#edit']);

          // Enabled checkbox.
          $this_row[] = drupal_render($map[$i]['table'][$id]['enabled']);

          // Add disabled class to differentiate.
          $disabled_rows[] = array(
            'data' => $this_row,
            'class' => array(
              'disabled',
            ),
          );
        }
      }

      // Only add tabledrag if there were plugins for that source.
      drupal_add_tabledrag($table_id, 'order', 'sibling', 'weight');
    }

    // Combine enabled and disabled rows.
    $table_rows = array_merge($table_rows, $disabled_rows);

    // Put action-link class on for fanciness sake.
    $add = '<ul class="feeds-tamper-add action-links"><li>' . $map[$i]['#add_link'] . '</li></ul>';

    // "Add plugin" link is the last row.
    $table_rows[] = array(
      'data' => array(
        array(
          'data' => $add,
          'colspan' => 7,
        ),
      ),
      'class' => array(
        'feeds-tamper-add',
      ),
    );

    // Table caption, in the form of source_name -> target_name1, target_name2
    $caption = $map[$i]['#title']['source'] . ' -> ' . implode(', ', $map[$i]['#title']['targets']);
    $table = array(
      '#theme' => 'table',
      '#header' => $header,
      '#rows' => $table_rows,
      '#caption' => $caption,
      '#sticky' => FALSE,
    );
    $table['#attributes']['id'] = $table_id;
    $table['#attached']['css'][] = drupal_get_path('module', 'feeds_tamper_ui') . '/feeds_tamper_ui.css';
    $map[$i]['table'] = $table;
    $map[$i]['#prefix'] = '<div class="feeds-tamper-table">';
    $map[$i]['#suffix'] = '</div>';
  }
  return drupal_render_children($form);
}