If the destination plugin is url_alias and we try to use the entity_lookup plugin for some reason, the following lines in the constructor lead to an error saying something like Entity type 1 does not exist..

$this->destinationEntityType = empty($pluginIdParts[1]) ?: $pluginIdParts[1];
this->destinationBundleKey = !$this->destinationEntityType ?: $this->entityManager->getDefinition($this->destinationEntityType)->getKey('bundle');

The problem is the ternary operator in the first line returns 1 if $pluginIdParts[1] is empty. So, the ternary operator should be like:

$this->destinationEntityType = empty($pluginIdParts[1]) ? NULL : $pluginIdParts[1];
$this->destinationBundleKey = !$this->destinationEntityType ? NULL : $this->entityManager->getDefinition($this->destinationEntityType)->getKey('bundle');
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jigarius created an issue. See original summary.

jigarius’s picture

Version: 8.x-3.x-dev » 8.x-4.x-dev
FileSize
1 KB

Switching to 8.x-4.x.

mvc’s picture

Status: Active » Needs review

This patch works for us; I'll let someone else set this to RTBC since I work with jigarius and this should be reviewed by someone at another organization.

heddn’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Great find. Bumping back to NW for tests. We're really trying hard to beef up testing on this.

marvil07’s picture

+1
The patch at #2 worked as expected. Another case for this is the book destination plugin, which does not have the bundle in the destination name.

marvil07’s picture

Assigned: jigarius » Unassigned
Status: Needs work » Needs review
Issue tags: -Needs tests
Related issues: +#2826636: Add non basic tests for entity lookup/generate plugins
FileSize
3.67 KB
2.66 KB

I understand the value of tests, but IMHO delaying applying a know fix to a known bug for this long may not be the best strategy for a contributed module.
Core may be different because of the amount of contributions it receives.

Here a test only patch that should fail, and the complete patch.

Also, linking a related ticket for tests on entity_lookup plugin.

Status: Needs review » Needs work

The last submitted patch, 6: 2896600-6-test_only.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

marvil07’s picture

Status: Needs work » Needs review
FileSize
3.67 KB
675 bytes

A small extra change related to coding standards.

  • heddn committed cbb509d on 8.x-4.x authored by marvil07
    Issue #2896600 by marvil07, jigarius, heddn: Entity lookup not working...
heddn’s picture

Status: Needs review » Fixed

Thanks for your contributions, especially the tests.

Changes made on commit:

     $this->destinationEntityType = empty($pluginIdParts[1]) ? NULL : $pluginIdParts[1];
-    $this->destinationBundleKey = !$this->destinationEntityType ? NULL : $this->entityManager->getDefinition($this->destinationEntityType)->getKey('bundle');
+    $this->destinationBundleKey = $this->destinationEntityType ? $this->entityManager->getDefinition($this->destinationEntityType)->getKey('bundle') : NULL;
   }
     $this->assertSame($known_user->id(), $value);
     // Check an unknown user is not found.
     $value = $plugin->transform('orange', $executable, $row, 'name');
-    $this->assertNotSame($known_user->id(), $value);
+    $this->assertNull($value);
   }

Status: Fixed » Closed (fixed)

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