Hello,

I hope this is the right place to put this bug report. I'm not sure if it's a panels, token, or entity token issue.

When rendering a block in a panel, I can succeed at most core drupal tokens. For example, [current-page:title] works fine. However, when I'm calling a custom field token (entity token) such as [node:field_email] in a content pane, the token does not render. Instead, the token is shown unrendered on the rendered page.

Is this indeed a bug or is it a misconfiguration or what? I appreciate your assistance. It's been a few days and I'm very close to launch! Getting the forms to work right is the last step - this is part of that step :-)

Jay

Comments

JayShoe’s picture

I can confirm that this is an issue with panels. I have a custom page at admin/structure/pages called node template (/node/%node). Using selection rules I show this custom panel page for a specific content type. Under the "contexts" area of the page, i see all the "tokens" (or whatever you want to call the contexts) listed. However, NONE of them actually work when called on a panel pane!

When I disable the panel page and load the node normally, the tokens work properly.

When I try to use "drupal standard" tookens, they work. Just not the "field_" tokens.

Does anyone know what I'm doing wrong? Is this broken? I've tried both the latest standard release of panels as well as the dev versions. Nothing works.

Thanks

jpoesen’s picture

I confirm as well: I have custom tokens that work perfectly on a standard node/x pageload, but as soon as I let panels page manager take that over with node/$nid and I use a custom content pane (rendering the fields with field_view_field()), the tokens are no longer replaced.

I'm trying to figure this one out. The closest I've com is that when my hook_tokens() implementation is called, the $data argument is empty. Since there's no 'context' being passed along, token substitution can't happen.

When I disable the page manager page and have a standard node/x page load again, the $data argument is properly passed along again.

--> somehow when an entity is loaded and rendered on a custom content page, its 'context' is lost when hook_tokens() is called?

jpoesen’s picture

EDIT: it would seem my previous comment was wrong: the way I was rendering the entities and fields in my custom content pane plugin was wrong.

It seems that field_view_field() will not trigger token substitution, whereas field_attach_view() *will*.

Not working (tokens in body field not substituted):

  $node = node_load($nid);
  $field = field_view_field('node', $node, 'field_body');

  $output = render($field);

Working:

  $node = node_load($nid);
  $renderable_node = field_attach_view('node', $node, 'full');

  $output = render($renderable_node['field_body']));

Not sure if it answers your question.
Hope it helps.

Dave Reid’s picture

I added a new node with Token filter enabled with a body text of 'This is the body of [node:title]'.

Given the following code above in #3, I got this output:

// field_view_field():
<div class="field field-name-body field-type-text-with-summary field-label-above"><div class="field-label">Body:&nbsp;</div><div class="field-items"><div class="field-item even" property="content:encoded"><p>This is the body of New article</p>
</div></div></div>
// field_attach_view():
<div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even" property="content:encoded"><p>This is the body of New article</p>
</div></div></div>

The node token was replaced in both instances.

Dave Reid’s picture

@jpoesen: I believe in your example, the field_view_field() call, by not passing an extra $display parameter, the default field formatter is used for the field, compared to your field_attach_view() call which uses the 'full' view mode configuration to render the field. These are two very different ways of displaying the field. If you wanted them to be "the same" then use field_view_field('node', $node, 'field_body', 'full');

jpoesen’s picture

Thanks Dave. I've tried passing along the display to field_view_field() in all sorts of ways, but keep arriving at the same result.

This is the first time I'm digging this deep in token and field stuff, so I'm probably making some wrong conclusions. I'll continue hunting down what is going wrong for me. Sorry if I've hijacked this thread.

EDIT: reproducing this scenario on a clean D7 still does not make field_view_field() trigger token replacement for me.

rrrob’s picture

I'm seeing something very similar.

I have a panels page where the page title is being set with a token. I am using the page title content pane.

When the token is %term:name, the title renders as it should. When the token is %term:field_whatever, then page title renders sometimes. Interestingly, the <title> element in <head> is correctly set.

On my local dev box running PHP 5.5 on OS X, the page title content pane always renders properly.

On the testing server running PHP 5.3 on Ubuntu, the page title content pane only renders after clearing Drupal's cache, and then only for a short while.

rroblik’s picture

Hi,

My workaround is the following :

function module_or_theme_preprocess_panels_pane(&$vars) {
  $vars['display']->title = ctools_context_keyword_substitute($vars['display']->title, array(),  $vars['display']->context);
}

I don't understand the source of this (very) old problem ...

Regards

granticusiv’s picture

So thankful I found this page. I thought I was having an issue with the Custom Tokens module not rendering embedded/contextual tokens. Turns out it was because I was rendering the page with Panels.

JayShoe’s picture

I just found this issue again while working on a site and my searches led me to this page.

rroblik, where does that code go to make it work? Should I make a custom module or something to over-ride this?

Is there any fix for this yet? I would imagine a lot of people run into this issue.

rroblik’s picture

@JayShoe as this topic is active I think there is no official fix for this problem.

My workaround can go where you want (in your theme template.php file or in a custom module)

Regards

aangel’s picture

For me calling ctools_context_keyword_substitute() in the preprocess function still wasn't working: it still wasn't replacing %title. Stepping through that function showed that there are two paths, one with a colon and one without. By using %node:title instead of just %title, the pane displays properly.

I had another issue that made the whole problem moot after all but I wanted to share the above in case it helps others.