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:

$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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

acrazyanimal’s picture

acrazyanimal’s picture

Status: Active » Needs review
acrazyanimal’s picture

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

gmclelland’s picture

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

gmclelland’s picture

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.

acrazyanimal’s picture

@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.

mgifford’s picture

Jelle_S’s picture

Status: Needs review » Reviewed & tested by the community

Patch applies and solves the error.

tauno’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
846 bytes

@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().

yannickoo’s picture

Status: Needs review » Reviewed & tested by the community

Patch from comment #9 fixed the notice, thanks!

acrazyanimal’s picture

@tauno good call. Your patch makes more sense.

mgifford’s picture

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

fago’s picture

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.