Hi

I added the like/dislike field to the CUSTOM comment type.
From the url "/admin/structure/comment/manage/CUSTOM/display" i have this:
IMAGE-Manage display.png

When i open my custom content type, i see this notices:
Notice: Undefined index: likes in Drupal\like_dislike\Plugin\Field\FieldFormatter\LikeDislikeFormatter->viewElements() (line 147 of modules/contrib/like_dislike/src/Plugin/Field/FieldFormatter/LikeDislikeFormatter.php).
and
Notice: Undefined index: dislikes in Drupal\like_dislike\Plugin\Field\FieldFormatter\LikeDislikeFormatter->viewElements() (line 148 of modules/contrib/like_dislike/src/Plugin/Field/FieldFormatter/LikeDislikeFormatter.php).

IMAGE-Content type.png
These notices are duplicate because there are only two comments per page.

Drupal Version: 9.3.0
"drupal/like_dislike": "^2.1"

IMAGE-Recent log messages.png

Comments

inman created an issue. See original summary.

Fanalea’s picture

Hey,

The easiest to fix the issue is to change line 147 and 148 in src/Plugin/Field/FieldFormatter/LikeDislikeFormatter.php.

$elements[] = [
      '#theme' => 'like_dislike',
      '#likes' => $initial_data['likes'],
      '#dislikes' => $initial_data['dislikes'],
      '#like_url' => $like_url,
      '#dislike_url' => $dislike_url,
      '#entity_id' => $initial_data['entity_id'],
];

You change this part of code to:

$elements[] = [
      '#theme' => 'like_dislike',
      '#likes' => $initial_data['likes'] ?? NULL,
      '#dislikes' => $initial_data['dislikes'] ?? NULL,
      '#like_url' => $like_url,
      '#dislike_url' => $dislike_url,
      '#entity_id' => $initial_data['entity_id'],
];
inman’s picture

Hello Fanalea!
Thank you, notices is missing.

I think it needs a patch.

anandhi karnan’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new767 bytes

Addressed #2 and here's a patch.

heykarthikwithu’s picture

Status: Needs review » Patch (to be ported)

It looks good, Thanks all :)

heykarthikwithu’s picture

Status: Patch (to be ported) » Fixed

Status: Fixed » Closed (fixed)

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