From 6b5a7ea4862154360dd9e479eb8f7302042e7391 Mon Sep 17 00:00:00 2001
From: megachriz <megachriz@654114.no-reply.drupal.org>
Date: Sat, 9 Jul 2016 10:21:10 +0200
Subject: [PATCH] Issue #2719151 by MegaChriz: Fixed don't retrieve title from
 feed if feed node does not use the node title field.

---
 feeds.module                  |  2 +-
 tests/feeds_content_type.test | 28 ++++++++++++++++++++++++++++
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/feeds.module b/feeds.module
index 061e0dd3..7cded509 100644
--- a/feeds.module
+++ b/feeds.module
@@ -609,7 +609,7 @@ function feeds_node_validate($node, $form, &$form_state) {
 
   // If the node title is empty and the title form element wasn't hidden, try to
   // retrieve the title from the feed.
-  if (trim($node->title) == '' && !$title_hidden) {
+  if (isset($node->title) && trim($node->title) == '' && !$title_hidden) {
     try {
       $source->addConfig($last_feeds);
       if (!$last_title = $source->preview()->title) {
diff --git a/tests/feeds_content_type.test b/tests/feeds_content_type.test
index 9fe67bde..4ee2b2aa 100644
--- a/tests/feeds_content_type.test
+++ b/tests/feeds_content_type.test
@@ -79,4 +79,32 @@ class FeedsContentTypeTest extends FeedsWebTestCase {
 
     $this->assertText('Title field is required.');
   }
+
+  /**
+   * Tests that the feed node gets no title if the content type does not use the
+   * node title field.
+   */
+  public function testWithContentTypeWithoutTitle() {
+    // Set that the content type 'page' has no title.
+    db_update('node_type')
+      ->fields(array(
+        'has_title' => 0,
+      ))
+      ->condition('type', 'page')
+      ->execute();
+
+    // Flush caches so this change is picked up.
+    drupal_flush_all_caches();
+
+    // And import a RSS feed with a title.
+    $edit = array(
+      'feeds[FeedsHTTPFetcher][source]' => $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'feeds') . '/tests/feeds/developmentseed.rss2',
+    );
+    $this->drupalPost('node/add/page', $edit, 'Save');
+
+    // Assert that the feed node didn't got a title from the source.
+    $node = node_load(1);
+    $this->assertEqual('', $node->title, 'The feed node has no title.');
+  }
+
 }
-- 
GitLab