1

I am trying to create/work on an Address target plugin for the Feeds module. I have tried applying this Address target patch (shown below) from this related issue. However, the Address field on the content type to which I am mapping feed sources does not appear as a target. I did try clearing the cache.

However, when I move this code, which attempts to create an Address field Feeds target, to the Feeds module, changing the namespace appropriately and placing it in feeds/src/Feeds/Target/Address.php, the Address field does appear as a target.

Question: Why is the patch below, written in the same style and using the same techniques as the other Feeds target plugins, not being discovered, even though the annotation seems to be correct to result in discovery? (Particularly given that it is discovered when it's patched into the Feeds module.)

Possibly relevant is: What changes in annotation discovery when a module is looking in other namespaces? I would think it should be discovered using AnnotatedClassDiscovery as defined in the D8 documentation, since it seems to have the appropriate annotation.

Edit: In case it's relevant, I have also tried removing both the prepareValue and prepareValues functions from the target class, per the Feeds maintainer's comments on the linked issue.

Here's the patch in question:

<?php

namespace Drupal\address\Feeds\Target;

use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\feeds\FieldTargetDefinition;
use Drupal\feeds\Exception\EmptyFeedException;
use Drupal\feeds\Exception\TargetValidationException;
use Drupal\feeds\Plugin\Type\Target\FieldTargetBase;

/**  
 * Defines a address field mapper.  
 *  
 * @FeedsTarget(  
 *   id = "address_feeds_target",  
 *   field_types = {"address"}  
 * )  
 */ 
class Address extends FieldTargetBase {

  /**    
   * {@inheritdoc}    
   */   
  protected static function prepareTarget(FieldDefinitionInterface $field_definition) {
    return FieldTargetDefinition::createFromFieldDefinition($field_definition)
      ->addProperty('langcode')
      ->addProperty('country_code')
      ->addProperty('administrative_area')
      ->addProperty('locality')
      ->addProperty('dependent_locality')
      ->addProperty('postal_code')
      ->addProperty('sorting_code')
      ->addProperty('address_line1')
      ->addProperty('address_line2')
      ->addProperty('organization')
      ->addProperty('given_name')
      ->addProperty('additional_name')
      ->addProperty('family_name');   
  }

}

closed as off-topic by leymannx, mradcliffe, sanzante, kiamlaluno Feb 12 at 14:45

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question was caused by a problem that can no longer be reproduced, was solved by a cache clear, or was a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers." – leymannx, mradcliffe, sanzante, kiamlaluno
If this question can be reworded to fit the rules in the help center, please edit the question.

  • It's likely a problem in your code. – Jaypan Feb 7 at 20:42
  • @Jaypan Can you clarify why you say that? Given that it works in the context of the Feeds module, but doesn't work when outside that context, I would think it would be unlikely to be the patch that I applied, which I assume is what you're referring to. – Travis Feb 7 at 21:02
  • 1
    I say that because your code isn’t working. Drupal does not discriminate - If code is written correctly Drupal will pick it up. – Jaypan Feb 7 at 21:03
  • 2
    Worked fine for me... Could be possible that you have 2 address modules in /modules somewhere. Perhaps accidentally moved inside another module? or perhaps even one in /core/modules. You could do a quick test and delete the address module folder, if you don't see any missing module errors, then indeed there is another address module folder somewhere. – No Sssweat Feb 8 at 14:41
  • 2
    Oh, wow... I cannot believe that was it. modules/address and modules/contrib/address... Thank you so much. I've never had that happen before nor do I know how that happened, but it did. – Travis Feb 8 at 17:24

Browse other questions tagged or ask your own question.