Drupal 7:创建一个RSS节点,每个节点有多个<item>?</item>

时间:2012-01-29 08:18:39

标签: drupal rss drupal-7 drupal-views mediarss

我的内容类型为“音频”,其中包含音频文件字段。该字段接受多个值,因此每个节点可以包含任意数量的音频文件。通常,当您构建RSS提要视图时,它将为每个节点生成一个<item>,并且每个节点将具有多个<enclosure>条目,每个音频文件一个。但就我的目的而言,我需要视图为每个音频文件值输出单独的<item>。因此,例如,如果所选节点中有3个音频文件,整个节点将在馈送中重复3次,每个节点只包含一个音频文件封装。

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

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

1 个答案:

答案 0 :(得分: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(例如)。可用的模板位于Views UI上第三个轨道(折叠的一个)底部的“主题”链接下。只需将视图模板文件拖放到主题文件夹中,然后点击全部。