0

I am building a drupal 7 (7.20) website with a "project" content type which contains multiple image fields (i do not want to use galleries).

I would like to be able to perform a mass delete operation on these fields from the node edit page. From what I have gathered I have to override theme_file_widget_multiple and return a tableselect instead of a table and then use a button plus javascript to delete the images from the database.

Am I missing something obvious ? This seems like alot of work for something so trivial.

EDIT:

I have had some progress with this:

function mytheme_file_widget_multiple($variables) {

$element = $variables ['element'];
$headers = array ();
$headers ['info'] = t ( '' );

$widgets = array ();
foreach ( element_children ( $element ) as $key ) {
    $widgets [] = &$element [$key];
}
usort ( $widgets, '_field_sort_items_value_helper' );

$rows [] = array ();
$i = 0;
foreach ( $widgets as $key => &$widget ) {
    // Save the uploading row for last.
    if ($widget ['#file'] == FALSE) {
        $widget ['#description'] = $element ['#file_upload_description'];
        continue;
    }
    $operations_elements = array ();
    foreach ( element_children ( $widget ) as $sub_key ) {
        if (isset ( $widget [$sub_key] ['#type'] ) && $widget [$sub_key] ['#type'] == 'submit') {
            $operations_elements [] = &$widget [$sub_key];
        }
    }
    $information = drupal_render ( $widget );
    $rows [$i ++] ['info'] = $information;
}

$output = '';
$output = drupal_render_children ( $element );
$form ['element'] = array (
    '#type' => 'tableselect',
    '#header' => $headers,
    '#options' => $rows,
    '#js_select' => TRUE,
    '#empty' => t ( 'No data' ),
    '#attributes' => array () );
$output .= empty ( $rows ) ? "" : drupal_render ( $form );
return $output;
}

This was included in my theme's template file however the tableselect does not have checkboxes. This is driving me crazy.. Can someone please tell me what I am doing wrong ?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129

1 Answers1

0

From what I have gathered I have to create a module which overrides the fieldset preprocess functions..

Here are the references:

1) https://drupal.org/node/1905244

This article seems to try to do what you want to.

2) Also check out https://drupal.org/project/views_bulk_operations this might be useful.

3) if not then you will need to make your own widget:

https://api.drupal.org/api/drupal/modules%21field%21field.module/group/field/7

https://drupal.org/project/examples ( has all the examples you will need )

all the best.

Vishal Khialani
  • 2,557
  • 6
  • 38
  • 49