Thanks for your effort on the D8 branch.

Problem/Motivation

I tried to test the module in Drupal 8. I encountered a problem when merging the terms. I get the following error.

Error: Call to a member function getValue() on null in Drupal\term_merge\TermMerger->migrateReference() (line 174 of modules/contrib/term_merge/src/TermMerger.php).

While investigating the issue I saw, that it tries to get the value of a field, that doesn't exist for currently processed entity. The reason is, that not every entity reference field to term exists for each node bundle. It becomes quite obvious when having a look into the actual code.

$referenceFieldNames = $this->findTermReferenceFieldNames();
$referencingEntities = $this->loadReferencingEntities($fromTerm);

foreach ($referencingEntities as $entity) {
  foreach ($referenceFieldNames as $fieldName) {
    $values = $entity->{$fieldName}->getValue();

Proposed resolution

Do a proper check, if the field exists, before trying to get the value.

Comments

szeidler created an issue. See original summary.

szeidler’s picture

Status: Active » Needs review
StatusFileSize
new496 bytes

Here's a straightforward fix for it.

tisteegz’s picture

I had this same issue and patch #2 worked for me.

Term merge - 8.x-1.0-alpha1
Drupal - 8.4.0

fredy davy stalin’s picture

StatusFileSize
new494 bytes

As per #2, hasField check did not resolve the issue. Should check if the field is empty or not. Also, I have modified the code.

legolasbo’s picture

Project: Term Merge » Term reference change
StatusFileSize
new4.75 KB

Moving this to Term reference change because that's where this functionality has moved and what term_merge will depend on in the near future.

Attached an updated patch with tests to cover this issue.

Status: Needs review » Needs work

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

legolasbo’s picture

Status: Needs work » Needs review
StatusFileSize
new4.9 KB

added missing test group

Status: Needs review » Needs work

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

legolasbo’s picture

StatusFileSize
new5.41 KB

that should be the final missing group annotation

legolasbo’s picture

Status: Needs work » Needs review
legolasbo’s picture

Committed and pushed to 8.x-1.x. Thanks for your help!

  • legolasbo committed 23a54da on 8.x-1.x
    Issue #2924083 by legolasbo, szeidler, Fredy Davy Stalin: Check if...
legolasbo’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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