- Issue created by @ttesteve
- First commit to issue fork.
- 🇫🇷France zewebmaster Nantes
Hi @ttesteve,
I face a similar problem when trying to use this module on a comment thread.
In my case, it turns out that in the Ajax callback
LikeForm::ajaxSubmit
, the entity embedded in the form validated (by clicking on the like button) always corresponds to my commented entity and not to the liked comment entity.# function LikeForm::ajaxSubmit /** @var \Drupal\Core\FieldItemInterface $item */ $item = $form['#item']; $entity = $item->getEntity();
I've tried to replicate the problem you describe by creating a very simple paginated view that displays teasers - as I understand your problem. And in the same way, the problem is quite similar and the entity loaded in the Ajax callback corresponds to the first item in the list of the current page and not to the liked entity => which causes the side effects you describe.
I've tried to correct the problem in several ways:
* By passing the entity into a field of type
value
=> This doesn't change anything!* By using fields of type
hidden
to retrieve the metadata of the liked entity and load it into the callback => this works, although I'm not sure it's the most appropriate way of doing it.I therefore propose this correction. Don't hesitate to let me know if it fixes the bug you're experiencing.
- 🇫🇷France zewebmaster Nantes
zewebmaster → changed the visibility of the branch 2.x to hidden.
- 🇬🇧United Kingdom ttesteve
Hi @zewebmaster,
I've just tested your fix on my site and it works perfectly now with multiple like buttons on the same page all now working as expected!
Many thanks for the solution!
- last update
6 months ago 6 pass