After upgrading to entity API 7.x-1.1 I can no longer override reply.tpl.php in a theme.
i get the error: Cannot use object of type Entity as array in C:\www\sandbox7\includes\common.inc on line 5786

it has to do with the render($content); call, when I comment that out of the template the page loads. But obviously there is no reply content rendered.

when I remove the file from the theme and let it load from the reply module, it works.

I've tried this with several themes and it breaks there too, so its not my custom theme. It happens using bartik.

Comments

Anonymous’s picture

Try this but I'm not sure it will work:

Replace line 784:

$vars['replies'][$reply->id]['#markup'] = theme('reply', array('elements' => array('reply' => $reply, 'display' => $vars['display'], 'access' => $vars['access'], 'allow_reply' => $vars['allow_reply'], 'bundle' => $vars['bundle'])));

with:

$vars['replies'][$reply->id] = array(
  '#theme' => 'reply',
  '#reply' => $reply,
  '#display' => $vars['display'],
  '#access' => $vars['access'],
  '#allow_reply' => $vars['allow_reply'],
  '#bundle' => $vars['bundle']
);
loze’s picture

thanks for the quick reply ivanjaros.
you're on to something but not quite there. This gets rid of the fatal error, but replies are not rendered.

The themes reply.tpl.php is loaded and output, but the render array is not rendered.
it appears that template_preprocess_reply() which sets up that $content variable never fires

And I get the following php warnings:

    Notice: Undefined index: #view_mode in template_preprocess_entity() (line 1019 of C:\www\sandbox7\sites\all\modules\contrib\entity\entity.module).
    Notice: Undefined index: #entity_type in template_preprocess_entity() (line 1020 of C:\www\sandbox7\sites\all\modules\contrib\entity\entity.module).
    Notice: Undefined index: #entity in template_preprocess_entity() (line 1022 of C:\www\sandbox7\sites\all\modules\contrib\entity\entity.module).
    Notice: Undefined index: #entity_type in template_preprocess_entity() (line 1023 of C:\www\sandbox7\sites\all\modules\contrib\entity\entity.module).
    Notice: Undefined index: entity keys in entity_extract_ids() (line 7627 of C:\www\sandbox7\includes\common.inc).
    Notice: Undefined index: entity keys in entity_extract_ids() (line 7628 of C:\www\sandbox7\includes\common.inc).
    Notice: Undefined index: entity keys in entity_extract_ids() (line 7627 of C:\www\sandbox7\includes\common.inc).
    Notice: Undefined index: entity keys in entity_extract_ids() (line 7628 of C:\www\sandbox7\includes\common.inc).
    Notice: Undefined index: entity keys in entity_id() (line 484 of C:\www\sandbox7\sites\all\modules\contrib\entity\entity.module).
    Notice: Undefined variable: reply in include() (line 5 of C:\www\sandbox7\themes\bartik\templates\reply.tpl.php).
    Notice: Trying to get property of non-object in include() (line 5 of C:\www\sandbox7\themes\bartik\templates\reply.tpl.php).
    Notice: Undefined index: #view_mode in template_preprocess_entity() (line 1019 of C:\www\sandbox7\sites\all\modules\contrib\entity\entity.module).
    Notice: Undefined index: #entity_type in template_preprocess_entity() (line 1020 of C:\www\sandbox7\sites\all\modules\contrib\entity\entity.module).
    Notice: Undefined index: #entity in template_preprocess_entity() (line 1022 of C:\www\sandbox7\sites\all\modules\contrib\entity\entity.module).
    Notice: Undefined index: #entity_type in template_preprocess_entity() (line 1023 of C:\www\sandbox7\sites\all\modules\contrib\entity\entity.module).
    Notice: Undefined index: entity keys in entity_extract_ids() (line 7627 of C:\www\sandbox7\includes\common.inc).
    Notice: Undefined index: entity keys in entity_extract_ids() (line 7628 of C:\www\sandbox7\includes\common.inc).
    Notice: Undefined index: entity keys in entity_extract_ids() (line 7627 of C:\www\sandbox7\includes\common.inc).
    Notice: Undefined index: entity keys in entity_extract_ids() (line 7628 of C:\www\sandbox7\includes\common.inc).
    Notice: Undefined index: entity keys in entity_id() (line 484 of C:\www\sandbox7\sites\all\modules\contrib\entity\entity.module).
    Notice: Undefined variable: reply in include() (line 5 of C:\www\sandbox7\themes\bartik\templates\reply.tpl.php).
    Notice: Trying to get property of non-object in include() (line 5 of C:\www\sandbox7\themes\bartik\templates\reply.tpl.php).
    Notice: Undefined index: #view_mode in template_preprocess_entity() (line 1019 of C:\www\sandbox7\sites\all\modules\contrib\entity\entity.module).
    Notice: Undefined index: #entity_type in template_preprocess_entity() (line 1020 of C:\www\sandbox7\sites\all\modules\contrib\entity\entity.module).
    Notice: Undefined index: #entity in template_preprocess_entity() (line 1022 of C:\www\sandbox7\sites\all\modules\contrib\entity\entity.module).
    Notice: Undefined index: #entity_type in template_preprocess_entity() (line 1023 of C:\www\sandbox7\sites\all\modules\contrib\entity\entity.module).
    Notice: Undefined index: entity keys in entity_extract_ids() (line 7627 of C:\www\sandbox7\includes\common.inc).
    Notice: Undefined index: entity keys in entity_extract_ids() (line 7628 of C:\www\sandbox7\includes\common.inc).
    Notice: Undefined index: entity keys in entity_extract_ids() (line 7627 of C:\www\sandbox7\includes\common.inc).
    Notice: Undefined index: entity keys in entity_extract_ids() (line 7628 of C:\www\sandbox7\includes\common.inc).
    Notice: Undefined index: entity keys in entity_id() (line 484 of C:\www\sandbox7\sites\all\modules\contrib\entity\entity.module).
    Notice: Undefined variable: reply in include() (line 5 of C:\www\sandbox7\themes\bartik\templates\reply.tpl.php).
    Notice: Trying to get property of non-object in include() (line 5 of C:\www\sandbox7\themes\bartik\templates\reply.tpl.php).
    Notice: Undefined index: #view_mode in template_preprocess_entity() (line 1019 of C:\www\sandbox7\sites\all\modules\contrib\entity\entity.module).
    Notice: Undefined index: #entity_type in template_preprocess_entity() (line 1020 of C:\www\sandbox7\sites\all\modules\contrib\entity\entity.module).
    Notice: Undefined index: #entity in template_preprocess_entity() (line 1022 of C:\www\sandbox7\sites\all\modules\contrib\entity\entity.module).
    Notice: Undefined index: #entity_type in template_preprocess_entity() (line 1023 of C:\www\sandbox7\sites\all\modules\contrib\entity\entity.module).
    Notice: Undefined index: entity keys in entity_extract_ids() (line 7627 of C:\www\sandbox7\includes\common.inc).
    Notice: Undefined index: entity keys in entity_extract_ids() (line 7628 of C:\www\sandbox7\includes\common.inc).
    Notice: Undefined index: entity keys in entity_extract_ids() (line 7627 of C:\www\sandbox7\includes\common.inc).
    Notice: Undefined index: entity keys in entity_extract_ids() (line 7628 of C:\www\sandbox7\includes\common.inc).
    Notice: Undefined index: entity keys in entity_id() (line 484 of C:\www\sandbox7\sites\all\modules\contrib\entity\entity.module).
    Notice: Undefined variable: reply in include() (line 5 of C:\www\sandbox7\themes\bartik\templates\reply.tpl.php).
    Notice: Trying to get property of non-object in include() (line 5 of C:\www\sandbox7\themes\bartik\templates\reply.tpl.php).
    Notice: Undefined index: #view_mode in template_preprocess_entity() (line 1019 of C:\www\sandbox7\sites\all\modules\contrib\entity\entity.module).
    Notice: Undefined index: #entity_type in template_preprocess_entity() (line 1020 of C:\www\sandbox7\sites\all\modules\contrib\entity\entity.module).
    Notice: Undefined index: #entity in template_preprocess_entity() (line 1022 of C:\www\sandbox7\sites\all\modules\contrib\entity\entity.module).
    Notice: Undefined index: #entity_type in template_preprocess_entity() (line 1023 of C:\www\sandbox7\sites\all\modules\contrib\entity\entity.module).
    Notice: Undefined index: entity keys in entity_extract_ids() (line 7627 of C:\www\sandbox7\includes\common.inc).
    Notice: Undefined index: entity keys in entity_extract_ids() (line 7628 of C:\www\sandbox7\includes\common.inc).
    Notice: Undefined index: entity keys in entity_extract_ids() (line 7627 of C:\www\sandbox7\includes\common.inc).
    Notice: Undefined index: entity keys in entity_extract_ids() (line 7628 of C:\www\sandbox7\includes\common.inc).
    Notice: Undefined index: entity keys in entity_id() (line 484 of C:\www\sandbox7\sites\all\modules\contrib\entity\entity.module).
    Notice: Undefined variable: reply in include() (line 5 of C:\www\sandbox7\themes\bartik\templates\reply.tpl.php).
    Notice: Trying to get property of non-object in include() (line 5 of C:\www\sandbox7\themes\bartik\templates\reply.tpl.php).

Thanks for your help on this!

loze’s picture

I think this may have to do with the theme function being the same name as the entity?
and its possibly colliding with template_preprocess_ENTITY() ?

when I change "reply" to "reply_single" in the hook_theme and the template file name and the preprocess function, it works.

the "Undefined index: #view_mode in template_preprocess_entity()" is what gave me a clue to this.

maybe I've just been looking at this too long. But, it does work the way I've described.

is it possible that the latest version of entity introduced this?

james.williams’s picture

This commit: http://drupalcode.org/project/entity.git/commitdiff/0fb1486b55e1bfae075d... did change something in entity module between 1.0 and 1.1 which might affect things? I'm not sure I understand how the 'patterns' property of the theme hooks works without stepping through the code in heavy detail.
I'm surprised that template_preprocess_entity is being run though here anyway -- that's the bit that I'd want to see investigated, as the reply module should be theming its own entities without the Entity module interfering at that point.

Anonymous’s picture

Yeah. It seems they are trying just too much and it's counterproductive.

loze’s picture

I think this is the root of it http://drupal.org/node/939462 ?

What should we do in the meantime?

loze’s picture

We shouldn't need to do this, but setting the 'base hook' in hook_theme_registry_alter() does fix it.
setting it in hook_theme itself did not work.

function reply_theme_registry_alter(&$theme_registry){
  $theme_registry['reply']['base hook'] = 'reply';
}
SebCorbin’s picture

I think Reply should rely on the basic rendering of entities.
Meaning I'm all for the usage of a wrapper (i.e. theme_replies) but for the inner reply theming we should stick to reply_view().
My problem was that I wanted to add extra_fields to reply entities but hook_entity_view was never fired due to the usage of its own theme function.

What I did :

-      $vars['replies'][$reply->id]['#markup'] = theme('reply', array('elements' => array('reply' => $reply, 'display' => $vars['display'], 'access' => $vars['access'], 'allow_reply' => $vars['allow_reply'], 'bundle' => $vars['bundle'])));
+      $vars['replies'][$reply->id] = reply_view($reply);
+      $vars['replies'][$reply->id]['access'] = $vars['access'];

But I'm still struggling with the way content is handled, render arrays added in $entity->content are not rendered with reply entities this way :

/**
 * Implements hook_entity_view().
 */
function like_entity_view($entity, $type, $view_mode, $langcode) {
    $entity->content['likes'] = array(
      '#likes' => !empty($entity->likes) ? $entity->likes : array(),
      '#entity_id' => $entity_id,
      '#entity_type' => $type,
      '#account' => $user,
      '#weight' => 10,
      '#theme' => 'likes_widget',
    );
}

I think this is due to the preprocess function, I'll try to provide a patch

SebCorbin’s picture

StatusFileSize
new3.84 KB

Patch attached

SebCorbin’s picture

Status: Active » Needs review
StatusFileSize
new3.99 KB

'reply' theme key is not necessary anymore as EntityAPI takes care of preprocessing/templating/rendering

mrharolda’s picture

Status: Needs review » Needs work
modules/contrib/reply$ patch -p1 --dry-run < 1994298-10-overriding-reply-tpl.patch 
patching file reply.module
Hunk #1 succeeded at 230 (offset 8 lines).
Hunk #2 succeeded at 803 (offset 8 lines).
Hunk #3 succeeded at 846 (offset 8 lines).
Hunk #4 succeeded at 868 (offset 8 lines).
Hunk #5 succeeded at 905 (offset 8 lines).
Hunk #6 succeeded at 1490 (offset 40 lines).
patching file reply.tpl.php
Hunk #1 FAILED at 1.
1 out of 1 hunk FAILED -- saving rejects to file reply.tpl.php.rej

The offsets could be due to the fact that I'm using today's -dev instead of a git checkout.

This part of the patch is a bit strange though, did you replace newlines?

diff --git a/reply.tpl.php b/reply.tpl.php
index ee97266..f2c156b 100644
--- a/reply.tpl.php
+++ b/reply.tpl.php
@@ -1,4 +1,4 @@
-<div id="reply-<?php print $reply->id ?>" class="<?php print $classes ?>">
-  <div class="reply-body"><?php print render($content) ?></div>
-  <div class="reply-links"><?php print render($links) ?></div>
-</div>
\ No newline at end of file
+<div id="reply-<?php print $reply->id ?>" class="<?php print $classes ?>">
+  <div class="reply-body"><?php print render($content) ?></div>
+  <div class="reply-links"><?php print render($links) ?></div>
+</div>
mrharolda’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new3.42 KB

I've removed reply.tpl.php from the patch to speed up the process ...

Too bad I can't set it to RBTC myself as it works perfectly ;)

SebCorbin’s picture

Status: Needs work » Reviewed & tested by the community

Yes, there was some problem with line endings. Thanks for the reroll :)

Paul B’s picture

Status: Needs review » Needs work

With the patch in #12 my reply.tpl.php is missing variables. It seems the _preprocess_reply hooks aren't being run.

mrharolda’s picture

Status: Needs work » Reviewed & tested by the community

@Paul B, I think you should use TEMPLATE_preprocess_entity(), like all other entities known to Drupal.

Works for me ...

SebCorbin’s picture

Due to the fact that we delete the 'reply' theme key, you have to work with YOURTHEME_preprocess_entity()

/**
 * Implements hook_preprocess_entity().
 */
function mytheme_preprocess_entity(&$vars) {
  // Get entity
  $entity = $vars['elements']['#entity'];
  $vars['entity_id'] = entity_id($vars['entity_type'], $entity);

  if ($vars['entity_type'] == 'reply') {
    // Do your stuff...
  }
}
Paul B’s picture

Status: Reviewed & tested by the community » Needs work

OK, but one of the variables I'm missing is 'links', which was not set up in my _preprocess_reply() implementations.
It used to be set up by template_preprocess_reply() I believe. That function is not being executed, though template_preprocess_replies() is.

Paul B’s picture

Status: Needs work » Needs review
StatusFileSize
new5.34 KB

I guess template_preprocess_reply() should become reply_preprocess_entity(). This patch works for me.

mrharolda’s picture

Off-topic: Someone should strip all weird line-endings and trailing spaces before we continue fixing this module. Almost half of the patch is unneeded.

Some code style fixes would be great too.

drupalgideon’s picture

StatusFileSize
new30.1 KB

Cleaned up version of patch in #18 attached as requested by #19. Run through Coder too .

mrharolda’s picture

@SkidNCrashwell: nice one!

I hope to check it soon, this is quite a welcome patch that really needs to go in -dev asap.

jamesharv’s picture

The patch in #18 solved this for me, but the one in #20 wouldn't apply against 7.x-1.x, or against the latest dev release.

Paul B’s picture

StatusFileSize
new24.06 KB

The patch in #20 seems to be corrupted. Here's a patch that just removes trailing whitespace and converts line endings.

nancydru’s picture

#1605242: Pass coder review fixes coding styles, please do not mix patches.

nancydru’s picture

Issue summary: View changes
Status: Needs review » Needs work

I am very much in favor of #10 or #18 (no other mixed in changes).

Paul B’s picture

None of the patches in #10, #18 and #1605242: Pass coder review apply anymore.
The maintainer should give fixing his linebreaks more priority.

Anonymous’s picture

Line endings were fine until one commit(not mine). But I can't find it anymore.
Anyway, I won't be committing any new patches until this issue is fixed so I'll wait for RTBC patch.

Sorry, seems the line endings were from my commits, specifically:
http://drupalcode.org/project/reply.git/commitdiff/db507297cc869225c54c3...
and recently http://drupalcode.org/project/reply.git/commit/e37f3028a93ec018dd20f2e36...
which is strange because I haven't change my IDE settings at all. In the second one I was removing a previous commit(ajax functionality) so maybe it has something to do with it but the first one is still a mystery to me.

I'm using Netbeans and it's build-in GIT support. Any tips to avoid this issue again are welcomed.

mrharolda’s picture

Maybe the 'autocrlf' is missing in your ~/.gitconfig?

[core]
	autocrlf = input

Note: this only affects new files, not already commited ones.

https://help.github.com/articles/dealing-with-line-endings

Paul B’s picture

Status: Needs work » Postponed

This should wait until #2148045 is committed.

nancydru’s picture

[#2148045) is fixed. Can the submitters re-roll this patch?

Paul B’s picture

Assigned: Unassigned » Paul B
Status: Postponed » Active
Paul B’s picture

Status: Active » Needs review
StatusFileSize
new3.98 KB

Re-rolled patch.

Paul B’s picture

Assigned: Paul B » Unassigned
nancydru’s picture

Closed #2168819: Trying to get property of non-object in reply_label() as duplicate.

Confirmed that #7 sort of fixes it for me.

josesanmartin’s picture

Status: Needs review » Fixed

The last patch fixes it for me as well. It's been commited, marking this as fixed.

Status: Fixed » Closed (fixed)

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

mihai_brb’s picture

This patch messed up the theme for me, as well as reply links (these I noticed).
I did not looked into the code but reverting e350ac727aaeaff51c5d8555822ffec49bff180a fixed it.

Any insight?
Thanks

hyperglide’s picture

@mihai_brb if that is the case you may wish to reopen this issue or perhaps better to create a new issue and link the (2) together.

mihai_brb’s picture

Hello again,
I think the problem is related to the fact that reply entities no longer go trough reply_preprocess_entity and therefor the links and classes are no longer added.

Is there a way to fix this other then adding links in the template for each reply entity?
Maybe use hook_entity_view_alter instead to add those links?

Thanks,
Mihai