We have a vocabulary with the description set to render into a Block region via the ds_extras module, but the description is not being displayed. When we change the description to display in the "content" region, it renders fine, but disappears when set to any of the blocks.

Looking over the code, it looks like this is due to the use of hook_field_attach_view_alter to create the content of that the Block region block content. That allows any fields attached to the entity to be rendered into the block content, but it does not include the description (example Krumo output of $build and $context is attached to this post).

I've taken a stab at adding the description from the $context argument, but I'm (a) not sure that's the right place to do it and (b) not sure how to add the description to the render array in a way that it's rendered properly. Here's what I have, it adds the description to the block_data array correctly, and is picked up at the hook_block_view implementation, but the description is (unsurprisingly) not rendered:

  if ($layout = ds_get_layout($entity_type, $bundle, $view_mode)) {
    foreach ($region_blocks as $block_key => $block) {
      if ($block['info'] == "{$entity_type}_{$bundle}_{$view_mode}" && isset($layout['settings']['regions'][$block_key]) && !empty($layout['settings']['regions'][$block_key])) {
        foreach ($layout['settings']['regions'][$block_key] as $key => $field) {
          if (isset($build[$field])) {
            $block_data[$block_key][$field] = $build[$field];
            unset($build[$field]);
          }
          elseif ($field == 'description' && isset($context['entity']->$field)) {
            $block_data[$block_key][$field] = $context['entity']->$field;
          }
        }
        if (is_array($block_data[$block_key])) {
          $block_data[$block_key] += $properties;
        }
      }
    }
  }

Where is the Description properly added to the render array (where is it removed by DS)? What's the best hook to use to attach it? How can we get the correct render array for just the description to add?

Comments

ethanw’s picture

Judging by taxonomy_term_view, it looks like ds_extras_entity_view_alter is the correct place for this logic to go.

I'm working on a patch for that, but am curious if the entire block assignment code couldn't effectively be moved to entity_view_alter, where the taxonomy render array will be fully populated. Any thoughts?

ethanw’s picture

Status: Active » Needs review
StatusFileSize
new4.4 KB

I was able to copy the code from ds_extras_field_attach_view_alter into ds_extras_entity_view_alter with fairly little modification. The two main changes made were:

  1. Using $build['#view_mode'] instead of $context['#view_mode'] since the latter doesn't exist in the entity_view_alter hook
  2. Only passing a subset of the entity's properties on to the block content render arrays, since passing them all caused rendering to fail. It looks like the viewterm entity has been embellished a bit more at the later hook stage, and while we have access to the complete description array, we need to be selective about the properties we pass.
swentel’s picture

Hmm, yeah, taxonomy_term_view() is adding the description later on, that's why it isn't found yet. I'll do some testing this weekend.

swentel’s picture

Status: Needs review » Closed (won't fix)