Hi,

I found a small bug in the userpoints_create_description() function.

Problem

On the page with list of all transactions (for example, user/%uid/points) module displays a transactions' descriptions. And if transaction refers to an entity, userpoints wraps the description with the entity url. Please, see this code from userpoints_create_description():

  // Link to the referenced entity, if available.
  if ($entity && $options['link']) {
    $uri = entity_uri($transaction->entity_type, $entity);
    if (isset($uri)) {
      $description = l($description, $uri['path'], $uri['options'] + array('html' => $safe, 'attributes' => $attributes));
    }
  }

Everything seems to be good - if we got a $uri, then we should be able to create a link. But please take a look at the latest lines of entity_uri() function:

  // Invoke the callback to get the URI. If there is no callback, return NULL.
  if (isset($uri_callback) && function_exists($uri_callback)) {
    $uri = $uri_callback($entity);
    // Pass the entity data to url() so that alter functions do not need to
    // lookup this entity again.
    $uri['options']['entity_type'] = $entity_type;
    $uri['options']['entity'] = $entity;
    return $uri;
  }

We see here, that no matter what result will be recieved from $uri_callback() function - $uri['options'] will be added anyway. And that's why if $uri_callback() returns FALSE (for example, due to access restrictions), we will not have a $uri['path'] key in the array. But userpoints_create_description() relies on this key. So if such case happens, I'll see php message "Notice: Undefined index: path in userpoints_create_description()", and the description will be linked to the front page.

Example

For example, I grant user a points for purchasing a commerce products. And, of cource, add this product as an entity to the transaction. But entity_uri() for the commerce product link refers to the product edit page. But ordinary users should not see this page. That's why I want to keep this link for admins, but I want to see no link for normal users. Without this patch I will see a php warning and link to the front page (for a normal user).

Proposed solution

I think that the proper way to solve this - is just to check if $uri['path'] key is exists. See attached patch.

CommentFileSizeAuthor
userpoints-undefined-index-path.patch566 bytesspleshka

Comments

spleshka’s picture

Issue summary: View changes
skdrupal88’s picture

Status: Needs review » Reviewed & tested by the community

Works good for me, lets commit it.

a.milkovsky’s picture

works for me too!

spleshka’s picture

Any progress in this issue?

spleshka’s picture

Any feedback from maintainers so far?

  • Berdir committed 05edaf0 on 7.x-1.x authored by Spleshka
    Issue #2161711 by Spleshka: Notice: Undefined index: path in...
berdir’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Not quite sure why this is needed but fine, committed. Not sure if it applies to 7.x-2.x as well.