Here's my site structure:

  • A vocabulary "keyword" has an entity reference field to beans to display multiple blocks which is named "Content blocks."
  • The Panels term_view has a variant for that vocabulary.
  • The term_view page has five regions: a top region, a bottom region, and three regions in the middle to make a three-column display.
  • In each column I've added a pane for the entity reference field and have it hardcoded to show a specific item, so the first column shows the first bean from the reference field, the second column shows the second bean, the third shows the third bean.

The problem is as follows: when beans are added to the entityreference field the panes display the name of the field, e.g. "Content blocks", not the title of the bean itself.

Comments

damienmckenna’s picture

I'm not sure this should be in the module, but here's the code I used to do it:

/**
 * Implements template_preprocess_panels_pane().
 *
 * Fix the pane title for beans loaded via entityreference fields.
 */
function mymodule_preprocess_panels_pane(&$variables) {
  $pane = $variables['pane'];

  // Only work with entityreference field panes.
  if ($pane->type == 'entity_field' && $variables['content']['#field_type'] == 'entityreference') {
    // Look for a bean object.
    foreach ($variables['content'] as $outer_key => $element) {
      if (is_numeric($outer_key) && array_key_exists('bean', $element)) {
        foreach ($element['bean'] as $key_inner => $bean_array) {
          $bean = $bean_array['#entity'];

          // Fix the title.
          $variables['content']['#title'] = $bean->title;
          $variables['title'] = $bean->title;

          // This will only work with one element in the array.
          break 2;
        }
      }
    }
  }
}
damienmckenna’s picture

Component: Code » Documentation
Category: bug » support

I think this is by design. Maybe something like this might be worth adding to a HowTo part of the documentation?