Commit 8dc0f01a authored by webchick's avatar webchick
Browse files

Issue #666412 by tayzlor, jaffaralia, iflista, mfb, xjm: Fixed Regression: RSS...

Issue #666412 by tayzlor, jaffaralia, iflista, mfb, xjm: Fixed Regression: RSS feed enclosure support lost from core.
parent 453b2517
......@@ -327,6 +327,10 @@ function file_field_formatter_info() {
'label' => t('URL to file'),
'field types' => array('file'),
),
'file_rss_enclosure' => array(
'label' => t('RSS enclosure'),
'field types' => array('file'),
),
);
}
......@@ -924,6 +928,24 @@ function file_field_formatter_view($entity_type, $entity, $field, $instance, $la
);
}
break;
case 'file_rss_enclosure':
// Add the first file as an enclosure to the RSS item. RSS allows only one
// enclosure per item. See: http://en.wikipedia.org/wiki/RSS_enclosure
foreach ($items as $item) {
if ($item['display']) {
$entity->rss_elements[] = array(
'key' => 'enclosure',
'attributes' => array(
'url' => file_create_url($item['uri']),
'length' => $item['filesize'],
'type' => $item['filemime'],
),
);
break;
}
}
break;
}
return $element;
......
<?php
/**
* @file
* Definition of Drupal\file\Tests\FileFieldDisplayTest.
*/
namespace Drupal\file\Tests;
/**
* Tests that formatters are working properly.
*/
class FileFieldRSSContentTest extends FileFieldTestBase {
public static function getInfo() {
return array(
'name' => 'File field RSS content',
'description' => 'Ensure that files added to nodes appear correctly in RSS feeds.',
'group' => 'File',
);
}
/**
* Tests RSS enclosure formatter display for RSS feeds.
*/
function testFileFieldRSSContent() {
$field_name = strtolower($this->randomName());
$type_name = 'article';
$field_settings = array(
'display_field' => '1',
'display_default' => '1',
);
$instance_settings = array(
'description_field' => '1',
);
$widget_settings = array();
$this->createFileField($field_name, $type_name, $field_settings, $instance_settings, $widget_settings);
$field = field_info_field($field_name);
$instance = field_info_instance('node', $field_name, $type_name);
// RSS display must be added manually.
$this->drupalGet("admin/structure/types/manage/$type_name/display");
$edit = array(
"view_modes_custom[rss]" => '1',
);
$this->drupalPost(NULL, $edit, t('Save'));
// Change the format to 'RSS enclosure'.
$this->drupalGet("admin/structure/types/manage/$type_name/display/rss");
$edit = array("fields[$field_name][type]" => 'file_rss_enclosure');
$this->drupalPost(NULL, $edit, t('Save'));
// Create a new node with a file field set. Promote to frontpage
// needs to be set so this node will appear in the RSS feed.
$node = $this->drupalCreateNode(array('type' => $type_name, 'promote' => 1));
$test_file = $this->getTestFile('text');
// Create a new node with the uploaded file.
$nid = $this->uploadNodeFile($test_file, $field_name, $node->nid);
// Get the uploaded file from the node.
$node = node_load($nid, TRUE);
$node_file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']);
// Check that the RSS enclosure appears in the RSS feed.
$this->drupalGet('rss.xml');
$uploaded_filename = str_replace('public://', '', $node_file->uri);
$test_element = array(
'key' => 'enclosure',
'value' => "",
'attributes' => array(
'url' => url("$this->public_files_directory/$uploaded_filename", array('absolute' => TRUE)),
'length' => $node_file->filesize,
'type' => $node_file->filemime
),
);
$this->assertRaw(format_xml_elements(array($test_element)), 'File field RSS enclosure is displayed when viewing the RSS feed.');
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment