我正在构建一个drupal 7(7.20)网站,该网站的"项目"内容类型包含多个图像字段(我不想使用库)。
我希望能够从节点编辑页面对这些字段执行大规模删除操作。根据我收集到的信息,我必须覆盖theme_file_idget_multure,并返回tableselect而不是表,然后使用按钮和javascript从数据库中删除图像。
我是不是错过了一些显而易见的东西?对于如此琐碎的事情来说,这似乎是一项艰巨的工作。
编辑:
我在这方面取得了一些进展:
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;
}
这包含在我的主题的模板文件中,但是tableselect没有复选框。这把我逼疯了。。有人能告诉我我做错了什么吗?
根据我收集到的信息,我必须创建一个模块来覆盖字段集预处理函数。。
以下是参考资料:
1)https://drupal.org/node/1905244
这篇文章似乎试图做你想做的事。
2) 同时查看https://drupal.org/project/views_bulk_operations这可能是有用的。
3) 如果没有,那么你将需要制作自己的小工具:
https://api.drupal.org/api/drupal/modules%21field%21field.module/group/field/7
https://drupal.org/project/examples(有你需要的所有例子)
一切都好。