With the taxonomy reference field removed (see change record https://www.drupal.org/node/2456869), the FeedsTarget "taxonomy" no longer can be used. As a result, the option "autocreate" is gone for taxonomy references and the test \Drupal\feeds\Tests\Feeds\RssNodeImport fails.

To fix this problem, somehow the FeedsTarget "taxonomy" should be used for when the target type of the entity reference field is "taxonomy_term". In other cases the FeedsTarget "entity_reference" should be used for entity reference fields.

A first patch will follow.

CommentFileSizeAuthor
#1 feeds-taxonomy-mapper-2476115-1.patch4.04 KBMegaChriz
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

MegaChriz’s picture

Status: Active » Needs review
FileSize
4.04 KB

I've now tried to fix this problem by setting the FeedsTarget "taxonomy" field type to "entity_reference". This initially caused that this FeedsTarget got used for all entity reference fields. To fix this, I overrided the method targets() to return only targets when the field's target type is "taxonomy_term".
This doesn't look like the best solution, because first the FeedsTarget "entity_reference" will register targets for all fields of type "entity_reference" and later on the FeedsTarget "taxonomy" will override the targets for fields that reference taxonomy terms, but only because "Taxonomy" is later in the alphabet than "EntityReference". I can imagine that contributed modules specifying their own entity type, sometimes want to provide specific options for referencing entities as well. Is there a better method of overriding already defined targets by an other FeedsTarget?

Details of the changes in the patch and their reasoning:

  • \Drupal\feeds\Feeds\Target\EntityReference:
    • Method getBundle() is changed into getBundles, because entitiy references now can target multiple bundles.
  • \Drupal\feeds\Feeds\Target\Taxonomy:
  • The test \Drupal\feeds\Tests\Feeds\RssNodeImport passes localy.
twistor’s picture

Could we just move the auto creation to the entity reference target and remove the taxonomy target?

  • twistor committed 69c87b3 on 8.x-3.x
    Issue #2476115 by MegaChriz: Restore the Taxonomy mapper
    
twistor’s picture

Status: Needs review » Fixed

Status: Fixed » Needs work

The last submitted patch, 1: feeds-taxonomy-mapper-2476115-1.patch, failed testing.

MegaChriz’s picture

Status: Needs work » Fixed

@twistor
The auto creation will not work for every entity type, because some entities may require more values than just the label.

Leaving state to "needs work" for now. Feel free to set the issue back to "fixed" if the concern above does not apply. I haven't tested the module yet with the latest changes.

MegaChriz’s picture

Status: Fixed » Needs work
twistor’s picture

Status: Needs work » Fixed

Status: Fixed » Closed (fixed)

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