The default entity template shows an error:

Notice: Undefined variable: url in include() (line 35 of /....../modules/entity/entity.tpl.php).

My code that calls entity_view is the following:

<?php
$block
['content'] = entity_view('organization', $employers, 'user_employer', NULL, FALSE);
?>

The issue is that entity.tpl.php always expects the 'url' variable, but depending on if $page is set in the original entity_view call, template_preprocess_entity may not 'set' that variable up. There are a few places that this could be fixed, but I think it makes the most sense to just check for it in the tpl file.

There are a couple other issues raised in other modules that I believe are this exact issue:
#1553398: Undefined variable: url
#1561392: Undefined variable: url

Files: 
CommentFileSizeAuthor
#9 entity-url-template-variable-1601162-9.patch846 bytestauno
PASSED: [[SimpleTest]]: [MySQL] 354 pass(es).
[ View ]
#3 entity-check-url-in-entity-template-1601162-1.patch732 bytesacrazyanimal
PASSED: [[SimpleTest]]: [MySQL] 354 pass(es).
[ View ]
#1 entity-check-url-in-entity-template-1601162.patch728 bytesacrazyanimal
PASSED: [[SimpleTest]]: [MySQL] 354 pass(es).
[ View ]

Comments

StatusFileSize
new728 bytes
PASSED: [[SimpleTest]]: [MySQL] 354 pass(es).
[ View ]

Status:Active» Needs review

StatusFileSize
new732 bytes
PASSED: [[SimpleTest]]: [MySQL] 354 pass(es).
[ View ]

Crud! messed up the commit message. Not that it really matters, but helps if you don't have to fix it up.

Thanks for posting this patch. I will try it out and see if it works.

Here is another related issue with EntityForm module:
#1491264: Notice when embedding the form with an Entity Reference Field

The patch in #3 applied but it didn't solve the problem with the issue posted in #4. I still get the same error message.

@gmclelland are you sure the patch applied. That should have fixed that particular problem. Check that the entity.tpl.php has the 'empty()' check in the if statement on line 35. empty() checks if the variable is set, so I don't see how you could still get that error if the patch did in fact apply?

[EDIT] : I see what is going on here. There is a second error posted in comment #4 of the issue you posted in this issue's comment #4. It is an identical issue caused by the Entity forms module's copying of the entity api's template file. The issue is in entityform.tpl.php and is an entityforms module issue, not entity api. So, we'll deal with it there, not here.

Status:Needs review» Reviewed & tested by the community

Patch applies and solves the error.

Status:Reviewed & tested by the community» Needs review
StatusFileSize
new846 bytes
PASSED: [[SimpleTest]]: [MySQL] 354 pass(es).
[ View ]

@acrazyanimal I think the url needs to be set if entitiy_view() is called with $page = FALSE or NULL. The only time you don't need the url is if it's a full page view. Easiest solution is to move a couple lines of code in template_preprocess_entity().

I specifically ran into this bug using the rendered entity display formatter on an entityreference field where entityreference also sets $page to FALSE when calling entity_view().

Status:Needs review» Reviewed & tested by the community

Patch from comment #9 fixed the notice, thanks!

@tauno good call. Your patch makes more sense.

Just checking that this is now in the repo and should thus be marked with a fixed status, right?

Status:Reviewed & tested by the community» Fixed

thanks #9 looks good, committed!

Status:Fixed» Closed (fixed)

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