When displaying Bean blocks in a view (using the block field 'Rendered Block') the Bean title field is never displayed. I know that the Bean title can be added as another field but this kind of defeats the usefulness of using entity view modes (and sadly doesn't quite fit my intended use case for a current project).

I had hoped that http://drupal.org/node/1836798 might have fixed the issue but sadly that was just wishful thinking.

Is this an easy fix?

#41 bean-title-should-be-movable-in-display-settings-185841-drupal-7-ua_quickstart.patch793 bytestrackleft2
#22 bean-n1858416-22.patch708 bytesidflood
PASSED: [[SimpleTest]]: [MySQL] 98 pass(es). View
#22 bean-n1858416-22-alt.patch843 bytesidflood
PASSED: [[SimpleTest]]: [MySQL] 98 pass(es). View
#19 bean-n1858416-19.patch643 bytesDamienMcKenna
PASSED: [[SimpleTest]]: [MySQL] 98 pass(es). View
#12 bean-display_the_title-1858416-12.patch552 bytesgabriel.achille
PASSED: [[SimpleTest]]: [MySQL] 98 pass(es). View
#8 bean-display_the_title-1858416-8.patch573 bytesdanielgmc
FAILED: [[SimpleTest]]: [MySQL] Invalid patch format in bean-display_the_title-1858416-8.patch. View
#24 bean-display_bean_title_with_class-1858416-24.patch766 bytesTyler the Creator
PASSED: [[SimpleTest]]: [MySQL] 98 pass(es). View
#27 bean-1858416-27-title-display.patch791 bytesmilesw
PASSED: [[SimpleTest]]: [MySQL] 98 pass(es). View
#28 bean-1858416-28-title-display.patch1.21 KBjohnnybgoode
PASSED: [[SimpleTest]]: [MySQL] 98 pass(es). View
Members fund testing for the Drupal project. Drupal Association Learn more


DamienMcKenna’s picture

This happens via EntityReference displays too (#1891210: Incompatible with entity reference formatter "Rendered Entity"), only the contents of the bean are displayed, the title is not.

DamienMcKenna’s picture

Title: Views field 'Rendered Block' does not display the Bean title » Rendered bean does not display the title when display settings indicate it should

Going through the logic..

The module allows you to control whether the title is displayed per view mode from admin/structure/block-types/manage/[beantype]/display, so therefore the title, like all fields, should adhere to the display settings for that view mode.

indytechcook’s picture

I see where you are going @DamienMcKenna, BTW, thanks and awesome work today!

The problem is the integration with the block module. Since the title is rendered separately, we would need to default to the title being hidden in the default display mode. This would integrate with "core" theming and such. Then a site that uses only beans could react to the bean differently? How does that sound?

DamienMcKenna’s picture

Shouldn't it be ok to just adhere to the bean's view mode display settings? I was digging around, might there be a way to change the title field's default formatter in bean_field_extra_fields() to 'hidden'?

akalata’s picture

Contextual links would also be awesome... oh wait, those are rendered with title-suffix aren't they? /d'oh!/

yechuah’s picture

Bean implements hook_field_extra_fields for title so it acts as if you can configure it in manage displays.

For that functionality to work though, the field needs to be part of $entity->content which 'title' is not.

put this in bean.module

function bean_entity_view($entity, $type, $view_mode, $langcode) {
  if ($type == 'bean') {
    $entity->content['title']['#markup'] = $entity->title;
mducharme’s picture

@yechuah Should we make a patch of this for inclusion in Bean?

danielgmc’s picture

Issue summary: View changes
573 bytes
FAILED: [[SimpleTest]]: [MySQL] Invalid patch format in bean-display_the_title-1858416-8.patch. View

I've used some of this code in one of my projects, so thanks!

Attaching a patch. The bean title will display as H2.

gabriel.achille’s picture

Status: Active » Needs review

set as "need review" for automatic test.

Status: Needs review » Needs work

The last submitted patch, 8: bean-display_the_title-1858416-8.patch, failed testing.

The last submitted patch, 8: bean-display_the_title-1858416-8.patch, failed testing.

gabriel.achille’s picture

Status: Needs work » Needs review
552 bytes
PASSED: [[SimpleTest]]: [MySQL] 98 pass(es). View

hmm... i just removed some Windows line endings and convert tab into spaces.
Let's try again.

Albert Volkman’s picture

Status: Needs review » Reviewed & tested by the community

Tested locally and confirmed functionality.

rerooting’s picture

hmm so for me this leads to duplicate block titles - one properly placed via entity display, and in the conventional block title position. this is with only bean and bean_admin_ui enabled, mind you

indytechcook’s picture

Status: Reviewed & tested by the community » Needs work

Setting to needs work per comment #14.

indytechcook’s picture

  1. +++ b/bean.module
    @@ -772,6 +772,19 @@ function bean_create($values) {
    + * Implements hook_entity_view()

    Have we tried doing this in bean_view rather than hook_entity_view? IMO this is not the proper use of that hook.

  2. +++ b/bean.module
    @@ -772,6 +772,19 @@ function bean_create($values) {
    +      '#tag' => 'h2',

    I'm not a fan of hard coding elements outside of a theme function.

rerooting’s picture

I think this same issue came up with fieldable panel panes as well - the duplicate entity title vs render title issue, specifically. The workaround as I recall was to have the pane at the preprocessing step look to see if the title was set in the entity, and then hide it's own title if the entity had a title set. I agree about #2, would prefer that the element not be hardcoded. Possibly a theme function should be written to handle it, similar to block title?

tragic.rich’s picture

*comment removed*

DamienMcKenna’s picture

Status: Needs work » Needs review
643 bytes
PASSED: [[SimpleTest]]: [MySQL] 98 pass(es). View

You mean something closer to this? I'm working on the same thing for the FPP module over in #2256503: Title field is not output when display settings indicate it should be.

DamienMcKenna’s picture

While it may not be the best approach to hardcode the HTML tag that's used, I think it's reasonable to use H2 as that's what block.tpl.php uses.

left’s picture

Hi, thanks for the work on this this. I really like Bean.

I've encountered the same issue - I don't get the bean block title displayed via Views using the rendered entity format, despite the title being set to visible.

I applied #19 patch to Bean 7.x-1.7

The title does appear but it falls outside and below the main div - see below.

<div class="views-row views-row-1 views-row-odd views-row-first">
  <div typeof="" about="/block/slide001" class="entity entity-bean bean-slide clearfix">
   <div class="content">
  <h2>Slide Title</h2>

It also makes the bean block title appear twice when not displayed via Views. This is ok because I can just set the block title to "none" to get only one instance, but if I didn't want a title at all, it would be problematic.

Maybe you are aware of this, or maybe I am doing something wrong. Please let me know if I can help in any way.
Many thanks!

idflood’s picture

708 bytes
PASSED: [[SimpleTest]]: [MySQL] 98 pass(es). View
843 bytes
PASSED: [[SimpleTest]]: [MySQL] 98 pass(es). View

I had the same issue as #21 with the patch in #19 so here is a new patch which add the title in the bean content. The only change is this:

$content['title'] = array(

// Become
$content_key = key($content['bean']);
$content['bean'][$content_key]['title'] = array(

Now the second title is displayed at the correct place. But there is a couple of issues with the first patch:

  1. It's not really backward compatible. Someone updating to a new version of the module may have the bad surprise to suddenly have all bean blocks with two titles.
  2. Semantically it seems wrong to have 2 identical titles in '< h2 >' tags. In panels it is fixable by 'overriding' the title with a blank one but it is not practical.

Possible double title fix

So I added a second patch (-alt) which also empty the "block" title. This fix the double title issue.

With the second patch the only problem is the backward compatibility. It could potentially break existing website but the risk is smaller than with the double title issue. I feel it is more correct, but you may need to bump the version to 2.x to indicate a "big" change (+ a warning on the project page maybe).

Tyler the Creator’s picture

bean-n1858416-22.patch worked for me. Thanks!

Tyler the Creator’s picture

766 bytes
PASSED: [[SimpleTest]]: [MySQL] 98 pass(es). View

Just a small thing, I added a class to the title tag for styling convenience. Patch based on #22 bean-n1858416-22.patch attached.

left’s picture

bean-n1858416-22-alt.patch and #24 both worked for me.
I can confirm bean-n1858416-22.patch works too, but I opted to use 22-alt.

Thanks idflood and Tyler Pepper for the efforts.

It's handy to see what you've added. I'm that much closer to contributing back because of it :)

venutip’s picture

Confirm that the patch in #24 works on 7.x-1.7 (did not test -dev).

milesw’s picture

791 bytes
PASSED: [[SimpleTest]]: [MySQL] 98 pass(es). View

Patch works for me as well, but it outputs empty h2 tags when there is no title used.

Here is a new version of #24 that avoids outputting empty tags.

johnnybgoode’s picture

1.21 KB
PASSED: [[SimpleTest]]: [MySQL] 98 pass(es). View

I like where idflood's second patch in #22 is headed, but I think instead of removing the title from the bean object in bean_view, it makes more sense to remove the title from the 'content' render array in hook_block_view to prevent the title from printing twice. This way the bean object stays intact throughout the rendering, and the block system functions as expected.

Here is a patch based on #27 that tries to do this.

rooby’s picture

I'm wondering why the fascination with using theme_html_tag and adding it to the content array.

There seems to be a consistent pattern elsewhere in Drupal that system title fields (not Field UI) are not part of the content array and are printed out in the template file.

Is there are reason we are not following this apparent convention?

johnnybgoode’s picture

@rooby, that convention is followed when a bean is rendered as a block (the bean title becomes the block's subject), however we are talking about including the title property when a bean is rendered by entity_view, separate from the block system. To simply print the bean title in bean.tpl.php would mean that, as the module is currently written, there is no way to prevent it from printing in the block context, and thus the title would be printed twice when beans are rendered as blocks.

It should be possible to provide a variable to the bean template when a bean is rendered as a block, which could be used to determine not to print the title in that context, similar to the $page flag in node.tpl.php.

agileadam’s picture

#28 worked to give me the bean's title field in entity reference's "Rendered entity" output. Thanks!

yareckon’s picture

As an outsider trying to integrate bean with other blocks, I just want bean to use the block template, and map the title up into block subject. It's another topic perhaps, but the bean.tpl.php seems pretty useless, and I wish that entity view bean just did a block view of the bean through the block template. Different bean bundles could then be differentiated by using template suggestions variations on the block template. Just my two cents from someone who just spent yesterday trying to get bean to behave like blocks for css and js code. No extra themeables!

tragic.rich’s picture

@yareckon, you should be able to accomplish whatever you need via the preprocess_block function. From there you can change the block title, add additional block classes, or whatever else you might need:

* Override or insert variables into the block templates.
function theme_preprocess_block(&$vars) {
    // For bean blocks.
    if($vars['block']->module == 'bean') {
        // Get the bean elements.
        $beans = $vars['elements']['bean'];
        // There is only 1 bean per block.
        $bean = $beans[reset(element_children($beans))];
        // Add bean type classes to the parent block.
        $vars['classes_array'][] = drupal_html_class('block-bean-' . $bean['#bundle']);
        // Add template suggestions for bean types.
        $vars['theme_hook_suggestions'][] = 'block__bean__' . $bean['#bundle'];
        /* block type specific code 
        if($bean['#bundle'] == 'xxxxx') {

You can set $vars['block']->subject to whatever you need, adjust the template being used, or even declare a custom template per bean block type.

I hope that helps!

indytechcook’s picture

rymcveigh’s picture

#28 also worked for me. Thanks everyone!

finn.lewis’s picture

#28 works for me too.
I am also rendering the bean blocks via entity reference on a node, using the default display mode.
Without the patch, no titles, with the patch, I see titles!

I've not tested rendering the blocks through the blocks ui, so I won't set to RTBC yet.

Drupal 7.38
Bean 7.x-1.9
Entity Reference 7.x-1.1

danbohea’s picture

Status: Needs review » Reviewed & tested by the community

Just tested #28 and it works fine for me too.

Drupal 7.34 (not my project!)
Bean 7.x-1.9

I tested:

- Beans displayed via Views
- Beans displayed via Views through Panels (Views pane)
- Beans displayed as blocks through Panels
- Beans display via the normal blocks system

All rendered as expected with Bean titles intact.

That's 4 of use confirming good results from the patch in #28. I'm gonna dare mark this as RTBC.

acrosman’s picture

Yeah #28 solved the problem for me as well. Appears ready to be committed.

Greg Boggs’s picture

Status: Reviewed & tested by the community » Needs work

I hate to set this one back to needs work, but after testing this, I think it has one more bug.

Steps to test:

First, apply the patch. Next, create a bean type with a text field and teaser view mode display. Next, set the title to be hidden in manage disable and set the text field to visible. Just to be 100% certain, set the default display mode not to display any fields or title. Next, create a bean in the teaser view mode and give it a title and body text. Finally, add the bean to the content region in blocks UI.


The expect results should be that JUST the text field will print in the content area of every page. The actual result is that you get both the title and the body even though title is set to be hidden in manage display.

askibinski’s picture

FYI: This problem does not exist when you use the title module (which replaces titles into real fields).

trackleft2’s picture

793 bytes
AlfTheCat’s picture

I've tried #41 but to no avail. I'm using the latest dev.

What I'm trying to accomplish is to render an image field above the title of the bean. What happens is I get the title as a block title, then the image, then the title again.

I'm using the title module as well since this is on a multi-lingual site.

Thanks for any help.

** edit the former patch also seems to cause a regression where the title is displayed twice, as the block title and as a field even though the field is hidden in the view mode configuration.

stijndmd’s picture

I didn't go through everything here. But release 7.x-1.11 doesn't seem to have this issue/bug anymore.
Am I missing something here?

Am not using title module either.