Modul install:
- Content Translation
1. Create an ECK Entity Type.
2. Create a bundle.
3. Add a entity reference field (content/nodes).
4. Go to admin/config/regional/content-language and check the Entity Type for Translations (with all fields).
5. Create content in the default language for the bundle with a reference to a node.
6. Translate this content in another language.
7. Try to edit the original content or the translated content, then you get this error:
Error: Call to undefined method Drupal\Core\Field\EntityReferenceFieldItemList::id() in Drupal\content_translation\ContentTranslationHandler->entityFormAlter() (line 442 of core/modules/content_translation/src/ContentTranslationHandler.php).
| Comment | File | Size | Author |
|---|---|---|---|
| #39 | 2673540-39.patch | 726 bytes | legolasbo |
| #34 | interdiff-2673540-18-34.txt | 320 bytes | manuel.adan |
| #34 | eck-right_getowner_impl-2673540-34.patch | 2.3 KB | manuel.adan |
| #22 | get_owner_fix-2673540-22.patch | 1.62 KB | slydevil |
| #18 | eck-translation_an_entity-2673540-18.patch | 1.94 KB | kamkejj |
Comments
Comment #2
handkerchiefComment #3
handkerchiefComment #4
lammensj commentedThe problem is not the entity reference field, but rather the way the owner of your content is retrieved. When the author of your entity type is configured to be multilingual, Drupal will call the getOwner function of the EckEntity class. Instead of returning a User, a List is presented because of the multilingualism.
If you look at the getOwnerId function inside that same class, you will see the correct implementation. The patch attached fixes this issue for the getOwner function.
Comment #7
lammensj commentedFixed the failing test.
Comment #8
legolasboI believe the tests are right and this "fix" is wrong. The tests clearly indicate that the user is allowed to view the content. However, the tests are now changed to indicate that the user now is no longer allowed to view that content?
Comment #9
Renee S commentedCan confirm this bug. It appears the fix is grabbing the original author of the entity. But is that desired behaviour? Shouldn't it get the author of the translation being edited?
UPDATE: was looking at the first patch. The second patch fixed my objection above :)
Comment #10
Renee S commentedRe the tests, I agree @legolasbo, it appears the tests were correct, except the last one: and it's the text that is wrong (the entity does belong to the user, should assert 200).
Comment #11
kamkejj commentedThe patch from #7 fixed my error as well, but the part of the patch that changed the Tests/AccessTest.php failed patching. From the comments from #8-#10 the tests didn't not need to be changed except for a word. I made a new patch that should now completely work and changes `$this->assertResponse(200, 'The user can delete content which not his own.');` to `$this->assertResponse(200, 'The user can delete content which is his own.');`
I believe this is what needed to be done.
Comment #12
kamkejj commentedComment #14
replicaobscuraNot positive, but I think the reason the tests are failing is that getOwnerId() is returning the entity key of the UID field, instead of the actual UID value. I could be wrong about that, but it seems like changing the return value in that method to something like
return $this->get('uid')->target_id(is it an entity reference? If not maybereturn $this->get('uid')->valueinstead) might resolve the test failures and result in the expected behavior when calling that method.I think the change to the tests in kamkejj's last patch are correct, but now we just need to make the test pass again.
Comment #15
kamkejj commentedNew patch to test from #14 comments.
Comment #16
kamkejj commentedComment #18
kamkejj commentedRe-worked number #7 to change the wording in the assert response text to match the other text for when not the owner.
Comment #19
kamkejj commentedComment #21
kamkejj commentedComment #22
slydevil commentedCreated a new patch, works as expected.
The errors reported above are present with or without my patch on the 8.5 branch, so they should not hold back the review of this patch.
Comment #24
slydevil commentedComment #25
replicaobscuraWhen you say the new patch works as expected, what did not work as expected using patch #18? That one has less test failures, and it fixes the issue for me.
I'm just curious what the purpose of the different approach is, and if the additional code is doing anything useful.
Comment #26
slydevil commentedI don't recall why the patch from #18 didn't work, but it didn't. Based on the comments from my code it looks like it has something to do with a multi-lingual setup and
$this->get('uid')returning a list rather than a single value.I've added the tests for the 8.4 branch and they all passed. As I stated in comment #22 the errors in the 8.5 branch exist with or without my patch and are unrelated to it.
I'm confident that my patch will fix your issue as well.
Comment #27
replicaobscuraThe patch in #18 already fixed the issue you mentioned by changing
$this->get('uid')into$this->get('uid')->entityso I'm not sure why you would be running into that issue still using that patch. It's still working properly on Drupal 8.5 for us on a multilingual site and seems sufficient to correct this issue.Comment #28
manuel.adan#18 also works for me.
I think it should be confirmed somehow.
May the "authored by" field was configured as translatable (at /admin/config/regional/content-language)?
Comment #29
arlina commentedPatch from #22 worked for me with Drupal 8.5. Thanks!
Comment #30
megachrizThis is also causes an issue in Feeds, which tries to call the method
isAnonymous()on the result of$entity->getOwner(). Closed #2979832: Call to undefined method Drupal\Core\Field\EntityReferenceFieldItemList::isAnonymous() in EntityProcessorBase->entitySaveAccess() as a duplicate.Comment #31
megachrizChanging title cause the issue is wider than just a translation issue.
Comment #32
murzThanks, patch from #22 works well and solve problem with importing Feeds into ECK entities.
Comment #33
phjouPatch from #22 works also for me when editing a translation of an eck with uid field.
Comment #34
manuel.adanThis is a #18 review. ECK entity types do not add a key for the "uid", so the patched method "getOwnerId" fails, since it expects that such entity key exists.
Having an entity key for the uid (author) is adequate, core entity types that have an owner base field define this key. The reviewed patch adds it, making getOwnerId work correctly. I also expect that it solves the failed "access own entity type" tests.
Comment #35
abasso commentedCan we get #22 re-rolled for 8.5 and submitted? Thanks!!!
Comment #36
phjou@abasso: The patch #22 is still valid for the latest commit of the dev branch and works also for the alpha3 version.
Comment #38
replicaobscuraIs #22 actually needed considering #34 fixes an issue with the patch in #18, which I think is a simpler way to solve the problem that is more in line with how other entity types tend to handle it? I haven't run into any issues with it yet, but if there is some reason for the more complex uid handling in #22 instead, I'd be curious what that reason is. Thanks for the clarification!
Comment #39
legolasboLet's give this a go.
Comment #40
rshafakian commentedHere are the steps I used to recreate the error:
I then started over with a fresh install of drupal and applied the patch to ECK and followed the same steps. No error! Great work!
Comment #42
legolasboCommitted and pushed to 8.x-1.x. Thanks for your help everyone!