- Issue created by @cmcintosh
- Assigned to john.oltman
- πΊπΈUnited States john.oltman
Thanks for the post @cmcintosh! Patch looks good, I want to reproduce this locally, will get back later this week. Would like to include a test with the fix, so may open an MR eventually, tbd.
- πΊπΈUnited States john.oltman
The problem is deeper - but I could only reproduce it by having the Registration field enabled for the teaser display. If you disable it, it will never call RegisterForm, because it never needs to render. So I think you probably meant to say that the field was enabled, with Registration form being the chosen Format for the field in that view mode.
I'll have a MR posted soon.
- @johnoltman opened merge request.
-
john.oltman β
committed 147b90a3 on 3.0.x
Issue #3401297: Host entity not set in Registration Form formatter in a...
-
john.oltman β
committed 147b90a3 on 3.0.x
- πΊπΈUnited States cmcintosh
I have seen it in both cases, additionally this is just a part of a bigger issue I think with how the form is working.
in setHostEntity(FormStateInterface $form_state), we are first checking if $form_state already has a host entity, if not we fall back to using routeMatch paramaters, which will fail in this situation: $this->getRouteMatch()->getParameters().
I think the more/better solution would be to add a third parameter onto the form method, that takes a \Drupal\Core\Entity\ContentEntityInterface object. Then in the Field Formatter, pass in the host entity when calling the form to be rendered. This would ensure that the host entity is always present.
- πΊπΈUnited States john.oltman
Thanks - you may have missed that I had already committed a fix roughly along the lines of what you are proposing. A third argument is not needed since the form state can be initialized with the host entity. I kept the setHostEntity function but only as a fallback for other callers. This is committed to the dev branch and will be in the next release.
- πΊπΈUnited States cmcintosh
Hey John, yes I saw that the patch was accepted. Thanks for that. I overlooked that function was accessible, so that should handle other cases. Thanks again.
- πΊπΈUnited States john.oltman
No problem. To clarify, although it was much appreciated, I did not use the patch since it was covering up the root cause. This is what I ended up doing which is basically your proposal to add the host entity to the form via the field formatter. https://git.drupalcode.org/project/registration/-/commit/147b90a39279e67...
- Status changed to Fixed
about 1 year ago 3:24am 15 November 2023 Automatically closed - issue fixed for 2 weeks with no activity.