Skip to content
Snippets Groups Projects
Commit 547303d8 authored by megachriz's avatar megachriz Committed by Megachriz
Browse files

Issue #2854548 by MegaChriz: Added warning when user has the "Attach to...

Issue #2854548 by MegaChriz: Added warning when user has the "Attach to content type" setting the same as the node processor's content type.
parent 544955b4
No related branches found
No related tags found
No related merge requests found
......@@ -247,6 +247,31 @@ class FeedsUIUserInterfaceTestCase extends FeedsWebTestCase {
)));
}
/**
* Tests if the user is warned when the importer is attached to the same
* content type as the one selected on the node processor.
*/
public function testWarningWhenAttachImporterToContentTypeAlsoOnTheNodeProcessor() {
// Create content type.
$type = $this->drupalCreateContentType();
$typename = $type->type;
// Create an importer.
$this->createImporterConfiguration('Test feed', 'test_feed');
// Attach to content type.
$this->setSettings('test_feed', NULL, array(
'content_type' => $typename,
));
// Select the same content type on the node processor.
$this->setSettings('test_feed', 'FeedsNodeProcessor', array(
'bundle' => $typename,
));
$this->assertText('The importer is attached to the same content type as the content type selected on the node processor. Unless you have a very advanced use case, these two should never be the same.');
}
public function testImporterImport() {
$name = $this->randomString();
$id = drupal_strtolower($this->randomName());
......
......@@ -181,9 +181,31 @@ class FeedsImporter extends FeedsConfigurable {
*/
public function validateConfig() {
$errors = parent::validateConfig();
$config = $this->getConfig();
// Check if "Attach to content type" setting is the same as content type on
// node processor.
if ($this->processor instanceof FeedsNodeProcessor) {
$processor_config = $this->processor->getConfig();
if ($processor_config['bundle'] == $config['content_type']) {
$message = t('The importer is attached to the same content type as the content type selected on the node processor. Unless you have a very advanced use case, these two should never be the same.');
if (!module_exists('feeds_news')) {
$message .= ' ' . t('Enable the Feeds News module for an example of how the "@content_type" setting can be used.', array(
'@content_type' => t('Attach to content type'),
));
}
elseif ($this->id != 'feed') {
$message .= ' ' . t('See the importer !importer_name (provided by the Feeds News module) for an example of how the "@content_type" setting can be used.', array(
'!importer_name' => l(check_plain(feeds_importer('feed')->config['name']), 'admin/structure/feeds/feed'),
'@content_type' => t('Attach to content type'),
));
}
$errors[] = $message;
}
}
// Check for a combination of incompatible settings.
$config = $this->getConfig();
if (!$config['import_on_create'] && empty($config['content_type'])) {
if ($config['import_period'] == FEEDS_SCHEDULE_NEVER) {
$errors[] = t('"@import_period" and "@import_on_create" are both turned off and the importer is not attached to a content type. Unless you have alternative methods of running imports for this importer, Feeds will not import anything for this importer.', array(
......
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