I am writing a module called Commerce Product Add-on that puts products as add-ons on the Add to Cart forms of other products. It works for the most part.

Part of what it does is add another view mode for product entities. This view mode is used for this context.

We call this to add the displayed product to the form, rendering the resulting array.

entity_view('commerce_product', array($product_add_on->product_id => $product_add_on),
                      'commerce_pado', $language->language, TRUE);

However, for people without the View Product permissions, like anonymous users it throws an error.

Notice: Undefined index: path in template_preprocess_entity() (line 1020 of /sites/all/modules/entity/entity.module).

So path is not being set. If I set the page parameter to FALSE, it still happens. Although it needs to be TRUE, so it doesn't render the product title.

Thanks.

CommentFileSizeAuthor
#5 1934382.entity_uri_path_check.patch954 bytesrszrama
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

orbistertius’s picture

I got the same error and asumed that the system is working but with the error.
so I changed the mentioned line intro:

//$variables['url'] = $uri ? url($uri['path'], $uri['options']) : FALSE;
$variables['url'] = $uri && isset($uri['path']) ? url($uri['path'], $uri['options']) : FALSE;

All in all there are problems with commerce and entity in some areas and since a lot of time. #1392654 for example.
Guess this is quiet similar.
Regards,

orbistertius’s picture

You posted the same error in commerce as well.
Here is the other solution mucho more for commerce.

thim’s picture

fago’s picture

rszrama’s picture

Title: Undefined index: path in template_preprocess_entity() » Accommodate core's failure to provide for NULL results from uri callbacks
Category: Bug report » Task
Issue summary: View changes
Status: Closed (duplicate) » Needs review
FileSize
954 bytes

Hey fago, I don't suppose we could consider adding this simple workaround to the core ambiguity re: NULL entity URIs? The docblock for entity_uri() indicates that it should return NULL if an entity has no URI, but in practice it only returns NULL if an entity does not have a valid uri callback. I know you've commented on the core issue, but core issues being what they are, in the meantime might we add this non-invasive isset() check to the Entity API itself?

joshmiller’s picture

I see this support request a LOT and having this cleaned up would be very beneficial for the whole Commerce Community.

pcambra’s picture

+1 to apply this workaround as "commerce community" :) this warning makes commerce recurring tests to fail.

pasive’s picture

+1 to apply this workaround for Drupal commerce. I think non-invasive isset() should resolve the problem.

@rszrama and others, this seems a recurring problem and relates quite a few issues together. Can, by common efforts, we resolve it at least for Entity/Drupal Commerce side as it really breaks tests and creates many UI issues on running projects.

P.S. non intrusive isset patch tough works well.

Chris Matthews’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

The 5 year old patch in #5 to entity.theme.inc does not apply to the latest entity 7.x-1.x-dev and (if still relevant) needs reroll.

Checking patch theme/entity.theme.inc...
error: while searching for:
  $variables['title'] = check_plain(entity_label($entity_type, $entity));

  $uri = entity_uri($entity_type, $entity);
  $variables['url'] = $uri ? url($uri['path'], $uri['options']) : FALSE;

  if (isset($variables['elements']['#page'])) {
    // If set by the caller, respect the page property.

error: patch failed: theme/entity.theme.inc:169
error: theme/entity.theme.inc: patch does not apply
shubham.prakash’s picture

This issue has been fixed and no longer valid.

shubham.prakash’s picture

Status: Needs work » Fixed

Status: Fixed » Closed (fixed)

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