In the Drupal7 version it was possible to map to referenced entities using GUID and URL of the target item, this should be ported to 8.x version as well. I started working on this, it works but surely has issues too.

Drupal 7 entityreference was a contrib module that implemented entityreference_feeds_processor_targets_alter hook to provide these mappings. Now that entityreference is in core Feeds should provide these as it does for other core entities too.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Uhkis created an issue. See original summary.

Uhkis’s picture

Uhkis’s picture

Status: Active » Needs review
Uhkis’s picture

MegaChriz’s picture

Status: Needs review » Closed (works as designed)
FileSize
98.38 KB

This is already possible, though maybe a bit harder to find. In the D8 version the target is called "Feeds item".

mikran’s picture

Title: Add possibility to use GUID as mapping target » Add possibility to use GUID as unique entityreference target
Issue summary: View changes
Status: Closed (works as designed) » Needs review

Ok, the issue title & description is bad, let me try to re-write that.

mikran’s picture

FileSize
66.05 KB

And here is an image too. I've created one importer to import taxonomy terms and then when I'm configuring another importer to imports articles I have an option to map source id to taxonomy term via feeds item GUID.

Tags being mapped on feeds importer

MegaChriz’s picture

Priority: Normal » Major

Ah, got it now. Yes, that would be an useful addition. And an essential one too, so bumping priority to major.

twistor’s picture

Status: Needs review » Needs work

I didn't do a full review, but this stood out.

+++ b/src/Feeds/Target/EntityReference.php
@@ -120,14 +128,32 @@ class EntityReference extends FieldTargetBase implements ConfigurableTargetInter
+  protected function findEntityByGuid($type, $guid) {
+     $object = db_select($type . '__feeds_item', 'fi')
+      ->condition('feeds_item_guid', $guid)
+      ->fields('fi', array('entity_id'))
+      ->execute()
+      ->fetchObject();
+      return empty($object) ? NULL : $object->entity_id;
+  }

Can this use entity query? We're trying very hard not to have any SQL specific code.

MegaChriz’s picture

Closed #2861190: Add GUID & id() to Refference mapping settings as a duplicate which seems to be requesting the same feature (and it also has a patch).

mikran’s picture

FileSize
1.85 KB
5.06 KB

Patch rerolled & updated to work with latest version. I didn't fix the query mentioned in #9 yet though.

MegaChriz’s picture

According to https://www.sitepoint.com/drupal-8-version-entityfieldquery/ it seems like something like the following could work? The EntityReference class gets the service 'entity.query' already injected.

$this->queryFactory->get($type)
  ->condition('feeds_item.guid', $guid)
  ->execute();

Do you want to try that out, mikran?

MegaChriz’s picture

Status: Needs work » Needs review
FileSize
7.23 KB
3.77 KB

Looked into this patch and I made the following changes:

  • findEntityByGuid() now uses the injected query factory.
  • The get_class() is removed. When we receive an object we should not just check its exact class but use "instanceof". Ideally, we should check if it is an instance of a certain interface. That is also what this patch does. It checks if the field is an instance of DataDefinitionInterface to ensure it has a isComputed() method. FieldStorageDefinitionInterface doesn't extend DataDefinitionInterface so therefore the extra check.

I noticed also that the call to findEntityByGuid() fails with the following fatal error when querying against an entity type that does not have a feeds_item field:

Fatal error: Call to a member function getColumns() on boolean in /Websites/drupal/drupalsites/drupal8/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php on line 228

So we should in that method first check if the entity type does have that field.

Setting to "Needs review" so that the testbot evaluates the patch, but the status should be "Needs work" because of the concern noted above.

MegaChriz’s picture

This fixes the concern noted in #13: before executing the entity query with a condition on the feeds_item field, first is checked if the target entity type has a feeds_item field.

juho-jaakkola’s picture

I'm not able to import anything with the latest patch (feeds-reference-by-guid-2788631-14.patch). Not yet sure why.

mikran’s picture

Small patch. I think this should fix the problem in #15. FALSE is a not valid value for entity_reference so use null as no value instead.

Also I noticed that we don't have any test coverage at all for entity_reference target.

juho-jaakkola’s picture

This fixes a misnamed variable in the patch number 16. I can confirm that with this fix the patch works as intended.

Green light from me for merging the patch with this fix.

PunamShelke’s picture

HI,

Patch No 17 is working for...

  • MegaChriz committed 9e3c536 on 8.x-3.x authored by Uhkis
    Issue #2788631 by MegaChriz, mikran, juho-jaakkola, Uhkis: Added...
MegaChriz’s picture

Status: Needs review » Fixed

I have been using this patch for a while and did not notice any disruptiveness.

Committed #17.

Status: Fixed » Closed (fixed)

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

scott.whittaker’s picture

Sorry to necro a closed issue, but how do you set this up? I've made an importer for a node type and then another importer for another node type which has entity reference fields from the first node type. I want to be able to use this to map fields to the nested entity reference via the importer I set up for that type, but I can't figure out how to set up the mappings.

I can get the interface shown in #5 from adding a "Feeds item" target, but can't get any further than that, I'm not even able to get an interface like that shown in #7.