Problem/Motivation
Follow up from: https://www.drupal.org/node/2888268#comment-12309100
After applying above patch. I was able to use follow link in ajaxified way but got following error.
The website encountered an unexpected error. Please try again later.
TypeError: Argument 1 passed to Drupal\flag\Plugin\views\field\FlagViewsLinkField::renderLink() must implement interface Drupal\Core\Entity\EntityInterface, null given, called in /home/**/**/html/modules/contrib/flag/src/Plugin/views/field/FlagViewsLinkField.php on line 76 in Drupal\flag\Plugin\views\field\FlagViewsLinkField->renderLink() (line 114 of modules/contrib/flag/src/Plugin/views/field/FlagViewsLinkField.php).
This crash also happens when there is a flag link on a view that displays alongside other entites that do not have the flaggable entity in the reference field.
Steps to reproduce
- add a products flag,
- have a content view that displays content with a product relationship,
- add a products flag link to the view,
- display one piece of contentin the view without the product.
- crash,
Proposed resolution
Fix the above issue if reproducible.
Identify if there's a testing gap, fill it.
Remaining tasks
Create patch.
User interface changes
None.
API changes
None, probably.
Data model changes
None.
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | null_passed_to_ajaxfied-2917836-10.patch | 531 bytes | acrollet |
| #4 | null_passed_to_ ajaxfied-2917836-4.patch | 531 bytes | v_twix |
Comments
Comment #2
socketwench commentedI tried to reproduce this myself, but I didn't have any luck. :-(
Comment #3
pradeepjha commentedI tried this simple condition then it's looking fine.
public function render(ResultRow $values) {
$entity = $this->getParentRelationshipEntity($values);
if (empty($entity)) {
return '';
}else{
return $this->renderLink($entity, $values);
}
}
Comment #4
v_twix commentedTry to use this patch.
Comment #5
neurer commentedPatch at #4 fixed it for me. Thank you.
Comment #6
webdesgnr14 commentedWhen using composer and cweagans/composer-patches to manage patches, this patch won't apply due to mismatch of directories.
If you're having this issue try the attached patch:
(Also omitted space in file name)
Comment #7
webdesgnr14 commentedFile edit!
Comment #8
webdesgnr14 commentedPlease disregard, I'm being a doof today!
Comment #9
martin107 commentedlooking at the internals of your patch
a/core/modules/contrib/flag/src/Plugin/views/field/FlagViewsLinkField.php
b/core/modules/contrib/flag/src/Plugin/views/field/FlagViewsLinkField.php
it looks like when you created the patch with
git diff 8.8.x new_branch > null_passed_to_ajaxfied-2917836-5.patch
you did so in the core directory ... if you descend into the contrib/flag directory and repeate the command
then it will be in a format that works.
I hope this helps
Also flag need to be a separate git repo ... that is with a .git file in the modeuls/contrib/flag directory.
to get the git repo ... if you are using composer then
composer require 'drupal/flag:4.x-dev'
just let me know if you have any questions.
Comment #10
acrollet commentedre-rolled
Comment #11
kimberleycgmI had a case where I had multiple relationships to multiple entity types (and multiple flag types) in one view, so when creating the flag link it was failing when the entities didn't match up. The above patch is working well for me for this scenario.
The logic itself makes sense too as it's just bringing forward a later check in \Drupal\flag\Plugin\views\field\FlagViewsLinkField::renderLink().
Marking as reviewed and tested.
Thanks.
Comment #12
tonytheferg commentedRan into something similar here, though not ajax related. Steps to reproduce in my issue. I'll test this patch, and if it fixes my problem, I'll close mine as a duplicate of this, and provide steps to reproduce.
Comment #13
tonytheferg commented#10 works.
Comment #14
berdirCommitted.