Skip to content
Snippets Groups Projects
Commit 2e7be18f authored by megachriz's avatar megachriz Committed by MegaChriz
Browse files

Issue #1621602 by MegaChriz, twistor: Fixed 'Could not retrieve title from...

Issue #1621602 by MegaChriz, twistor: Fixed 'Could not retrieve title from feed' error message for parsers that cannot provide a title from the source.
parent 7242ec24
No related branches found
No related tags found
No related merge requests found
......@@ -37,6 +37,7 @@ files[] = plugins/FeedsUserProcessor.inc
; Tests
files[] = tests/feeds.test
files[] = tests/common_syndication_parser.test
files[] = tests/feeds_content_type.test
files[] = tests/feeds_date_time.test
files[] = tests/feeds_mapper_date.test
files[] = tests/feeds_mapper_date_multiple.test
......
......@@ -688,11 +688,6 @@ function feeds_node_delete($node) {
*/
function feeds_form_node_form_alter(&$form, $form_state) {
if ($importer_id = feeds_get_importer_id($form['#node']->type)) {
// Set title to not required, try to retrieve it from feed.
if (isset($form['title'])) {
$form['title']['#required'] = FALSE;
}
// Enable uploads.
$form['#attributes']['enctype'] = 'multipart/form-data';
......@@ -706,6 +701,14 @@ function feeds_form_node_form_alter(&$form, $form_state) {
);
$form['feeds'] += $source->configForm($form_state);
$form['#feed_id'] = $importer_id;
// If the parser has support for delivering a source title, set node title
// to not required and try to retrieve it from the source if the node title
// is left empty by the user.
// @see feeds_node_validate()
if (isset($form['title']) && $source->importer()->parser->providesSourceTitle()) {
$form['title']['#required'] = FALSE;
}
}
}
......
......@@ -36,4 +36,13 @@ class FeedsOPMLParser extends FeedsParser {
),
) + parent::getMappingSources();
}
/**
* Overrides FeedsParser::providesSourceTitle().
*
* This parser supports retrieving a title from the source.
*/
public function providesSourceTitle() {
return TRUE;
}
}
......@@ -171,6 +171,20 @@ abstract class FeedsParser extends FeedsPlugin {
$item = $result->currentItem();
return isset($item[$element_key]) ? $item[$element_key] : '';
}
/**
* Returns if the parsed result can have a title.
*
* Parser classes should override this method in case they support a source
* title.
*
* @return bool
* TRUE if the parsed result can have a title.
* FALSE otherwise.
*/
public function providesSourceTitle() {
return FALSE;
}
}
/**
......
......@@ -215,6 +215,15 @@ class FeedsSimplePieParser extends FeedsParser {
) + parent::getMappingSources();
}
/**
* Overrides FeedsParser::providesSourceTitle().
*
* This parser supports retrieving a title from the source.
*/
public function providesSourceTitle() {
return TRUE;
}
/**
* Returns cache directory. Creates it if it doesn't exist.
*/
......
......@@ -78,4 +78,13 @@ class FeedsSyndicationParser extends FeedsParser {
),
) + parent::getMappingSources();
}
/**
* Overrides FeedsParser::providesSourceTitle().
*
* This parser supports retrieving a title from the source.
*/
public function providesSourceTitle() {
return TRUE;
}
}
<?php
/**
* @file
* Contains FeedsContentTypeTest.
*/
/**
* Tests for when an importer is attached to a content type.
*/
class FeedsContentTypeTest extends FeedsWebTestCase {
public static function getInfo() {
return array(
'name' => 'Feed content type',
'description' => 'Tests behavior for when an importer is attached to a content type.',
'group' => 'Feeds',
);
}
public function setUp() {
parent::setUp();
// Create an importer configuration.
$this->createImporterConfiguration('Syndication', 'syndication');
$this->addMappings('syndication',
array(
0 => array(
'source' => 'title',
'target' => 'title',
'unique' => FALSE,
),
1 => array(
'source' => 'description',
'target' => 'body',
),
2 => array(
'source' => 'timestamp',
'target' => 'created',
),
3 => array(
'source' => 'url',
'target' => 'url',
'unique' => TRUE,
),
4 => array(
'source' => 'guid',
'target' => 'guid',
'unique' => TRUE,
),
)
);
}
/**
* Tests if titles can be retrieved from a feed.
*/
public function testRetrieveTitleFromFeed() {
// The Common syndication parser supports retrieving title from feed.
$edit = array(
'feeds[FeedsHTTPFetcher][source]' => $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'feeds') . '/tests/feeds/developmentseed.rss2',
);
$this->drupalPost('node/add/page', $edit, 'Save');
$node = node_load(1);
$this->assertEqual('Development Seed - Technological Solutions for Progressive Organizations', $node->title, 'The title was retrieved from the feed.');
}
/**
* Tests if the node title is required when the CSV parser is used.
*/
public function testRequiredNodeTitleWithCSVParser() {
// Set parser to CSV.
$this->setPlugin('syndication', 'FeedsCSVParser');
$edit = array(
'feeds[FeedsHTTPFetcher][source]' => $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'feeds') . '/tests/feeds/content.csv',
);
$this->drupalPost('node/add/page', $edit, 'Save');
$this->assertText('Title field is required.');
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment