Download & Extend

Undefined variable: url in entity.tpl.php

Project:Entity API
Version:7.x-1.x-dev
Component:Entity CRUD controller
Category:bug report
Priority:normal
Assigned:acrazyanimal
Status:closed (fixed)

Issue Summary

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

Comments

#1

AttachmentSizeStatusTest resultOperations
entity-check-url-in-entity-template-1601162.patch728 bytesIdlePASSED: [[SimpleTest]]: [MySQL] 354 pass(es).View details

#2

Status:active» needs review

#3

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

AttachmentSizeStatusTest resultOperations
entity-check-url-in-entity-template-1601162-1.patch732 bytesIdlePASSED: [[SimpleTest]]: [MySQL] 354 pass(es).View details

#4

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

#5

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.

#6

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

#7

#8

Status:needs review» reviewed & tested by the community

Patch applies and solves the error.

#9

Status:reviewed & tested by the community» needs review

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

AttachmentSizeStatusTest resultOperations
entity-url-template-variable-1601162-9.patch846 bytesIdlePASSED: [[SimpleTest]]: [MySQL] 354 pass(es).View details

#10

Status:needs review» reviewed & tested by the community

Patch from comment #9 fixed the notice, thanks!

#11

@tauno good call. Your patch makes more sense.

#12

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

#13

Status:reviewed & tested by the community» fixed

thanks #9 looks good, committed!

#14

Status:fixed» closed (fixed)

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

nobody click here