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');
}
}