Class "Drupal\feeds\Feeds\Target\NameTarget" not found

Created on 4 May 2023, 12 months ago
Updated 9 May 2023, 12 months ago

Problem/Motivation

please assist me with an error related to the Drupal Feeds module.

It seems that there is a missing class called "NameTarget".
I am using:

  • Drupal version 9.5.8
  • Feeds version 3.0.0-beta3.

Here's the error message I'm seeing:

The website encountered an unexpected error. Please try again later.
Error: Class "Drupal\feeds\Feeds\Target\NameTarget" not found in Drupal\feeds\Entity\FeedType->getMappingTargets() (line 305 of modules/contrib/feeds/src/Entity/FeedType.php).
Drupal\feeds\Entity\FeedType->getMappingTargets() (Line: 83)
Drupal\feeds\Form\MappingForm->buildForm()
call_user_func_array() (Line: 534)
Drupal\Core\Form\FormBuilder->retrieveForm() (Line: 281)
Drupal\Core\Form\FormBuilder->buildForm() (Line: 73)
Drupal\Core\Controller\FormController->getContentResult()
call_user_func_array() (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 580)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 169)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 81)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 58)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 49)
Asm89\Stack\Cors->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 23)
Stack\StackedHttpKernel->handle() (Line: 718)
Drupal\Core\DrupalKernel->handle() (Line: 19)

Is complaining about line 305 of modules/contrib/feeds/src/Entity/FeedType.php. See the code below

    298   public function getMappingTargets() {
    299     if ($this->targets === NULL) {
    300       $this->targets = [];
    301       $definitions = \Drupal::service('plugin.manager.feeds.target')->getDefinitions();
    302 
    303       foreach ($definitions as $definition) {
    304         $class = $definition['class'];
    305         $class::targets($this->targets, $this, $definition);
    306       }
    307 
    308       \Drupal::moduleHandler()->alter('feeds_targets', $this->targets, $this);
    309     }
    310 
    311     return $this->targets;
    312   }

Steps to reproduce

  1. Enabled the Feeds and Feeds Log modules.
  2. Navigated to admin/structure/feeds and clicked "Add feed type".
  3. Entered the following information:
  • Name: test 1
  • Fetcher: Download from URL
  • Parser: RSS/Atom
  • Processor: Node
  • Content type: Person
  • Clicked "Save" and then "Add mappings", at which point the error occurred.
  • Proposed resolution

    Remaining tasks

    User interface changes

    API changes

    Data model changes

    πŸ’¬ Support request
    Status

    Fixed

    Component

    Code

    Created by

    πŸ‡ΊπŸ‡ΈUnited States mario.elias

    Live updates comments and jobs are added and updated live.
    Sign in to follow issues

    Comments & Activities

    • Issue created by @mario.elias
    • Status changed to Fixed 12 months ago
    • πŸ‡³πŸ‡±Netherlands MegaChriz

      I see that a class with that name exists in the Name β†’ module:
      https://git.drupalcode.org/project/name/-/blob/8.x-1.x/src/Feeds/Target/...

      But the namespace there is defined correctly.

      It looks like you are using a module that has an error in its name spacing. For example: if you have a module called "mymodule", it can have a file called mymodule/src/Feeds/Target/NameTarget.php that has the following line in it:

      namespace Drupal\feeds\Feeds\Target;
      

      Because the code is part of the module "mymodule" that should be instead:

      namespace Drupal\mymodule\Feeds\Target;
      

      So to fix this:

      1. Scan your files for the line "namespace Drupal\feeds\Feeds\Target".
      2. Correct the namespace in the file.
      3. If the module in question is a contributed module on drupal.org:
        1. Check first if you had patched this module. One way to check this is to compare your module's code with the official module's code. Go to the issue where the patch is on and report the namespace error. Maybe provide an updated patch if you can.
        2. If the code is already part of the module, search for an existing issue about this error in the module's issue queue.
        3. If you cannot find an existing issue about it, reopen this issue and move it to the project's queue.

      I hope this helps you further. If not, feel free to reopen this issue.

    • πŸ‡³πŸ‡±Netherlands MegaChriz

      In our conversation in Slack, it turned out to be that the cause of the issue was that a patch with code for the Name module was applied to Feeds instead.

      The drupal site's composer.json contained:

      "drupal/feeds": {
        "Add a new FeedsTarget plugin to make name fields mappable in feeds importers.": "https://www.drupal.org/files/issues/NameTarget-2785491-2.patch"
      },
      

      While that should have been at the time:

      "drupal/name": {
        "Add a new FeedsTarget plugin to make name fields mappable in feeds importers.": "https://www.drupal.org/files/issues/NameTarget-2785491-2.patch"
      },
      

      A similar patch like the one above has been committed to the Name module so it is no longer needed. See #2785491: Add a new FeedsTarget plugin to make name fields mappable in feeds importers. β†’

    • Automatically closed - issue fixed for 2 weeks with no activity.

    Production build https://api.contrib.social 0.62.1