2

我有一个包含音频文件字段的内容类型“音频”。该字段接受多个值,因此每个节点可以包含任意数量的音频文件。通常,当您构建一个 RSS 提要视图时,它会为每个节点生成一个<item>,每个节点都有多个<enclosure>条目,每个音频文件一个。<item>但出于我的目的,我需要视图为每个音频文件值单独输出。因此,例如,如果选定节点中有 3 个音频文件,则整个节点将在提要中重复 3 次,每个节点将仅包含一个音频文件附件。

这样做的原因是,在我的具体情况下,我hook_node_view()在自定义模块中使用将 MRSS 标记添加到视图生成的每个节点。因此,与其将音频文件包装在标签中,不如<enclosure>将它们包装在<media:content>标签中。<media:content>根据 MRSS 规范,每个条目不应超过一个,<item>除非它们代表相同的内容。这是因为其他标签喜欢<title><description>属于<media:content>同一个标签中的所有标签<item>。具有讽刺意味的是,自定义钩子是最简单的部分,但首先我需要让视图以我描述的方式输出节点。

那么有什么方法可以使用新的 Drupal 7 视图分组功能或其他方法来生成我正在寻找的输出?我很想知道诀窍!否则,我将不得不使用自定义菜单项并失去使用 Views 获得的所有优势(例如自动缓存和能够在 Views UI 中工作)。

4

1 回答 1

2

创建“文件”视图,然后在视图 UI 右侧的高级折叠字段集下,创建节点与文件的关系(连接)。

这是一个快速视图,您可以在此处复制并导入您的视图 ui:

<?php
    $view = new view;
    $view->name = 'test';
    $view->description = '';
    $view->tag = 'default';
    $view->base_table = 'file_managed';
    $view->human_name = 'test';
    $view->core = 7;
    $view->api_version = '3.0';
    $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

    /* Display: Master */
    $handler = $view->new_display('default', 'Master', 'default');
    $handler->display->display_options['title'] = 'test';
    $handler->display->display_options['access']['type'] = 'perm';
    $handler->display->display_options['cache']['type'] = 'none';
    $handler->display->display_options['query']['type'] = 'views_query';
    $handler->display->display_options['query']['options']['query_comment'] = FALSE;
    $handler->display->display_options['exposed_form']['type'] = 'basic';
    $handler->display->display_options['pager']['type'] = 'full';
    $handler->display->display_options['pager']['options']['items_per_page'] = '10';
    $handler->display->display_options['style_plugin'] = 'default';
    $handler->display->display_options['row_plugin'] = 'fields';
    /* Relationship: File Usage: Content */
    $handler->display->display_options['relationships']['file_to_node']['id'] = 'file_to_node';
    $handler->display->display_options['relationships']['file_to_node']['table'] = 'file_usage';
    $handler->display->display_options['relationships']['file_to_node']['field'] = 'file_to_node';
    $handler->display->display_options['relationships']['file_to_node']['required'] = 0;
    /* Field: File: Name */
    $handler->display->display_options['fields']['filename']['id'] = 'filename';
    $handler->display->display_options['fields']['filename']['table'] = 'file_managed';
    $handler->display->display_options['fields']['filename']['field'] = 'filename';
    $handler->display->display_options['fields']['filename']['label'] = '';
    $handler->display->display_options['fields']['filename']['alter']['alter_text'] = 0;
    $handler->display->display_options['fields']['filename']['alter']['make_link'] = 0;
    $handler->display->display_options['fields']['filename']['alter']['absolute'] = 0;
    $handler->display->display_options['fields']['filename']['alter']['word_boundary'] = 0;
    $handler->display->display_options['fields']['filename']['alter']['ellipsis'] = 0;
    $handler->display->display_options['fields']['filename']['alter']['strip_tags'] = 0;
    $handler->display->display_options['fields']['filename']['alter']['trim'] = 0;
    $handler->display->display_options['fields']['filename']['alter']['html'] = 0;
    $handler->display->display_options['fields']['filename']['hide_empty'] = 0;
    $handler->display->display_options['fields']['filename']['empty_zero'] = 0;
    $handler->display->display_options['fields']['filename']['link_to_file'] = 1;
    /* Field: Content: Body */
    $handler->display->display_options['fields']['body']['id'] = 'body';
    $handler->display->display_options['fields']['body']['table'] = 'field_data_body';
    $handler->display->display_options['fields']['body']['field'] = 'body';
    $handler->display->display_options['fields']['body']['relationship'] = 'file_to_node';
    /* Field: Content: Date */
    $handler->display->display_options['fields']['field_date']['id'] = 'field_date';
    $handler->display->display_options['fields']['field_date']['table'] = 'field_data_field_date';
    $handler->display->display_options['fields']['field_date']['field'] = 'field_date';
    $handler->display->display_options['fields']['field_date']['relationship'] = 'file_to_node';
    $handler->display->display_options['fields']['field_date']['alter']['alter_text'] = 0;
    $handler->display->display_options['fields']['field_date']['alter']['make_link'] = 0;
    $handler->display->display_options['fields']['field_date']['alter']['absolute'] = 0;
    $handler->display->display_options['fields']['field_date']['alter']['external'] = 0;
    $handler->display->display_options['fields']['field_date']['alter']['replace_spaces'] = 0;
    $handler->display->display_options['fields']['field_date']['alter']['trim_whitespace'] = 0;
    $handler->display->display_options['fields']['field_date']['alter']['nl2br'] = 0;
    $handler->display->display_options['fields']['field_date']['alter']['word_boundary'] = 1;
    $handler->display->display_options['fields']['field_date']['alter']['ellipsis'] = 1;
    $handler->display->display_options['fields']['field_date']['alter']['strip_tags'] = 0;
    $handler->display->display_options['fields']['field_date']['alter']['trim'] = 0;
    $handler->display->display_options['fields']['field_date']['alter']['html'] = 0;
    $handler->display->display_options['fields']['field_date']['element_label_colon'] = 1;
    $handler->display->display_options['fields']['field_date']['element_default_classes'] = 1;
    $handler->display->display_options['fields']['field_date']['hide_empty'] = 0;
    $handler->display->display_options['fields']['field_date']['empty_zero'] = 0;
    $handler->display->display_options['fields']['field_date']['hide_alter_empty'] = 1;
    $handler->display->display_options['fields']['field_date']['settings'] = array(
      'format_type' => 'long',
      'fromto' => 'both',
      'multiple_number' => '',
      'multiple_from' => '',
      'multiple_to' => '',
      'show_repeat_rule' => 'show',
    );
    $handler->display->display_options['fields']['field_date']['group_rows'] = 1;
    $handler->display->display_options['fields']['field_date']['delta_offset'] = '0';
    $handler->display->display_options['fields']['field_date']['delta_reversed'] = 0;
    $handler->display->display_options['fields']['field_date']['delta_first_last'] = 0;
    $handler->display->display_options['fields']['field_date']['field_api_classes'] = 0;
    /* Field: Content: Link */
    $handler->display->display_options['fields']['view_node']['id'] = 'view_node';
    $handler->display->display_options['fields']['view_node']['table'] = 'views_entity_node';
    $handler->display->display_options['fields']['view_node']['field'] = 'view_node';
    /* Field: Content: Title */
    $handler->display->display_options['fields']['title']['id'] = 'title';
    $handler->display->display_options['fields']['title']['table'] = 'node';
    $handler->display->display_options['fields']['title']['field'] = 'title';
    /* Sort criterion: File: Upload date */
    $handler->display->display_options['sorts']['timestamp']['id'] = 'timestamp';
    $handler->display->display_options['sorts']['timestamp']['table'] = 'file_managed';
    $handler->display->display_options['sorts']['timestamp']['field'] = 'timestamp';
    $handler->display->display_options['sorts']['timestamp']['order'] = 'DESC';

    /* Display: Page */
    $handler = $view->new_display('page', 'Page', 'page');
    $handler->display->display_options['path'] = 'test';

?>

至于围绕整个 RSS 打印输出的正确标记,您可以操作视图模板。要修改每条记录,请使用 views-view-fields--test.tpl.php(例如)。对于整个视图的包装器,请使用 views-view--test.tpl.php (例如)。可用的模板位于视图 UI 上第三个栏杆(折叠的栏杆)底部的“主题”链接下。只需将视图模板文件放入您的主题文件夹并全部抄送。

于 2012-01-30T06:27:00.197 回答