You are here

function theme_bg_image_ui_paths_table in Background Images 7

Theme the background image paths form into a table

1 theme call to theme_bg_image_ui_paths_table()
bg_image_ui_paths_form in bg_image_ui/bg_image_ui.module

File

bg_image_ui/bg_image_ui.module, line 193

Code

function theme_bg_image_ui_paths_table($args) {

  //dpm($args);
  drupal_add_css(drupal_get_path('module', 'bg_image_ui') . '/css/bg_image_ui.css');
  $form = $args['form'];
  $rows = array();
  $header = array(
    'Path',
    'Background Image Node',
    'Preview',
    'Remove',
    'Weight',
  );
  $output = drupal_render($form['description']);
  foreach (element_children($form['items']) as $key) {
    $form['items'][$key]['weight']['#attributes']['class'] = array(
      'bg-image-path-weight',
    );

    // Get the image for preview
    $image_path = bg_image_get_image_path_from_node($form['items'][$key]['nid']['#default_value'], FALSE);
    $preview = '';
    if ($image_path) {

      // Setup the args for theme_image_style
      $args = array(
        'style_name' => 'thumbnail',
        'path' => $image_path,
        'alt' => basename($image_path),
        'title' => basename($image_path),
      );
      $preview = theme('image_style', $args);
    }
    $row = array();
    $row[] = drupal_render($form['items'][$key]['path']);
    $row[] = drupal_render($form['items'][$key]['nid']);
    $row[] = $preview;
    $row[] = drupal_render($form['items'][$key]['remove']);
    $row[] = drupal_render($form['items'][$key]['weight']);
    $rows[] = array(
      'data' => $row,
      'class' => array(
        'bg-image-path',
        'draggable',
      ),
    );
  }
  $args = array(
    'header' => $header,
    'rows' => $rows,
    'attributes' => array(
      'id' => 'bg-image-paths-table',
    ),
  );
  $output .= theme('table', $args);
  $output .= drupal_render_children($form);
  drupal_add_tabledrag('bg-image-paths-table', 'order', 'sibling', 'bg-image-path-weight');
  return $output;
}