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.
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | 2924083-9.patch | 5.41 KB | legolasbo |
| #7 | 2924083-7.patch | 4.9 KB | legolasbo |
| #5 | 2924083-5.patch | 4.75 KB | legolasbo |
| #4 | check_if_empty-2924083-4.patch | 494 bytes | fredy davy stalin |
| #2 | term_merge-check_field_existence_on_reference_migration-2924083-2.patch | 496 bytes | szeidler |
Comments
Comment #2
szeidler commentedHere's a straightforward fix for it.
Comment #3
tisteegz commentedI had this same issue and patch #2 worked for me.
Term merge - 8.x-1.0-alpha1
Drupal - 8.4.0
Comment #4
fredy davy stalin commentedAs per #2, hasField check did not resolve the issue. Should check if the field is empty or not. Also, I have modified the code.
Comment #5
legolasboMoving 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.
Comment #7
legolasboadded missing test group
Comment #9
legolasbothat should be the final missing group annotation
Comment #10
legolasboComment #11
legolasboCommitted and pushed to 8.x-1.x. Thanks for your help!
Comment #13
legolasbo