I have a flag called feature and a flag called like, which uses dlike.

I create a new node, and then flag it with "feature".

Upon reload, an error appears:
Notice: Undefined index: like in dlike_append() (line 50 of /var/www/drupal/sites/all/modules/dlike/dlike.inc).

Then, if I "like" and reload again, it goes away.

Please help?

Comments

DrupalDesigner-1’s picture

+ 1

mediaformat’s picture

+ 1

Vlad Stratulat’s picture

+1
The problem here is because dlike uses flag_get_counts() function from flag module. This function count for flags in specific node and it doesn't matter which type of flag was made, like, abuse or whatever.
I think it's better to clone this function into dlike module and add flag filter to it. Something like:

->condition('f.name', $flag_name)

Here's how I handle it:
I cloned flag_get_counts() function from flag module with some changes as follows:

// I renamed function to avoid names conflict
function dlike_flag_get_counts($content_type, $content_id, $flag_name, $reset = FALSE) {
  static $counts;

  if ($reset) {
    $counts = array();
    if (!isset($content_type)) {
      return;
    }
  }

  if (!isset($counts[$content_type][$content_id])) {
    $counts[$content_type][$content_id] = array();
    $query = db_select('flags', 'f');
    $query->leftJoin('flag_counts', 'fc', 'f.fid = fc.fid');
    $result = $query
      ->fields('f', array('name'))
      ->fields('fc', array('count'))
      ->condition('f.name', $flag_name) // this is new flag filter condition
      ->condition('fc.content_type', $content_type)
      ->condition('fc.content_id', $content_id)
      ->execute();
    foreach ($result as $row) {
      $counts[$content_type][$content_id][$row->name] = $row->count;
    }
  }

  return $counts[$content_type][$content_id];
}

Then in dlike.inc file in line 51 I replaced this:

$dlike_append_count = flag_get_counts($flag_type, $content_id);

Into this

$dlike_append_count = dlike_flag_get_counts($flag_type, $content_id, $flag_name);

Hope this will help everyone and it will be implemented in dlike.

Cheers

sascher’s picture

Your fix works.

Thank you for the great module

leeotzu’s picture

Assigned: Unassigned » fotuzlab
aalireza’s picture

please make a path.

where shound put this code ?

<?php
// I renamed function to avoid names conflict
function dlike_flag_get_counts($content_type, $content_id, $flag_name, $reset = FALSE) {
  static $counts;

  if ($reset) {
    $counts = array();
    if (!isset($content_type)) {
      return;
    }
  }

  if (!isset($counts[$content_type][$content_id])) {
    $counts[$content_type][$content_id] = array();
    $query = db_select('flags', 'f');
    $query->leftJoin('flag_counts', 'fc', 'f.fid = fc.fid');
    $result = $query
      ->fields('f', array('name'))
      ->fields('fc', array('count'))
      ->condition('f.name', $flag_name) // this is new flag filter condition
      ->condition('fc.content_type', $content_type)
      ->condition('fc.content_id', $content_id)
      ->execute();
    foreach ($result as $row) {
      $counts[$content_type][$content_id][$row->name] = $row->count;
    }
  }

  return $counts[$content_type][$content_id];
}
?>
aalireza’s picture

Issue summary: View changes

Tweak

dankung1’s picture

after modify the dlike.inc file, the issue remains, I used the following code to created two flags at product display page. It shows undefiend index like .......

Is there a way to hide the PHP error message,
Notice: Undefined index: like in dlike_append() (line 50 of /var/www/drupal/sites/all/modules/dlike/dlike.inc).

@Vlad Stratulat

print flag_create_link('like', arg(1));
print flag_create_link('bookmarks', arg(1));
ReBa’s picture

Issue summary: View changes
StatusFileSize
new4.3 KB

I think this could be resolved by changing 1 line of code. Patch provided.

mediaformat’s picture

Status: Active » Needs review
flutterstack’s picture

Version: 7.x-1.1 » 7.x-2.x-dev
Assigned: fotuzlab » Unassigned
Status: Needs review » Reviewed & tested by the community

#8 is working fine for dlike 7x-2x.

anybody’s picture

I can confirm this problem sadly still exists for the 7.x-3.x version. Please also fix it there.

anybody’s picture

In 7.x-3.x version it seems to be just an isset-check which is missing.

gwereg’s picture

To fix it, in dlike.inc file, about line 47, just replace

if ($dlike_append_count  && $dlike_append_count[$flag_name] > 0) {

into this

if ($dlike_append_count && isset($dlike_append_count[$flag_name]) && $dlike_append_count[$flag_name] > 0) {
gokulnk’s picture

Version: 7.x-2.x-dev » 7.x-3.x-dev
sneyerst’s picture

StatusFileSize
new875 bytes

Patch for 7.x-3.0 attached.

majumdaraditya21@yahoo.in’s picture

Status: Reviewed & tested by the community » Needs work

Patch is not being applied . Needs reroll.

dieuwe’s picture

Status: Needs work » Needs review
StatusFileSize
new759 bytes

Try this, re-rolled against latest dev. I've removed the initial check to see if the variable exists, because isset() actually takes care of that.

  • dieuwe committed d0788d5 on 7.x-3.x
    Issue #1699352 by ReBa, sneyerst, dieuwe: Error with multiple flags
    
dieuwe’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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