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

  1. add a products flag,
  2. have a content view that displays content with a product relationship,
  3. add a products flag link to the view,
  4. display one piece of contentin the view without the product.
  5. 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.

Comments

socketwench created an issue. See original summary.

socketwench’s picture

I tried to reproduce this myself, but I didn't have any luck. :-(

pradeepjha’s picture

I 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);
}

}

v_twix’s picture

StatusFileSize
new531 bytes

Try to use this patch.

neurer’s picture

Patch at #4 fixed it for me. Thank you.

webdesgnr14’s picture

StatusFileSize
new608 bytes

When 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)

webdesgnr14’s picture

StatusFileSize
new634 bytes

File edit!

webdesgnr14’s picture

Please disregard, I'm being a doof today!

martin107’s picture

looking 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.

acrollet’s picture

Status: Active » Needs review
StatusFileSize
new531 bytes

re-rolled

kimberleycgm’s picture

Status: Needs review » Reviewed & tested by the community

I 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.

tonytheferg’s picture

Ran 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.

tonytheferg’s picture

Issue summary: View changes

#10 works.

berdir’s picture

Status: Reviewed & tested by the community » Fixed

Committed.

  • Berdir committed 34c4dcc on 8.x-4.x authored by acrollet
    Issue #2917836 by webdesgnr14, acrollet, Twix.: Null passed to AJAXified...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.