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.
| Comment | File | Size | Author |
|---|---|---|---|
| userpoints-undefined-index-path.patch | 566 bytes | spleshka |
Comments
Comment #1
spleshkaComment #2
skdrupal88Works good for me, lets commit it.
Comment #3
a.milkovskyworks for me too!
Comment #4
spleshkaAny progress in this issue?
Comment #5
spleshkaAny feedback from maintainers so far?
Comment #7
berdirNot quite sure why this is needed but fine, committed. Not sure if it applies to 7.x-2.x as well.