Problem/Motivation

Hello,

I tried to render a book reference entity type in another view mode. But this do not render anything.

Steps to reproduce
- Create a new view mode for reference entity type. Let's call it "Teaser"
- Enable this view mode and configure it to show only some few fields
- Create a view and choose to render entities based on the Teaser mode

When rendering reference entity in another view mode, fields are rendered separatly, field by field, without a global wrapper with attributes. It's not possible to theme each reference.

Proposed resolution

After looking at the code, it looks like bibcite_entity do not provide a default template for bibcite_reference and there is not some basic preprocessing to provide variables to this template. There is only a custom template bibcite_reference_table (note the simple _ where as should be bibcite_reference__table - with 2 __ if this template was referering to the view mode table for bibcite_reference entity).

Looks like the issue is from the ReferenceViewBuilder

protected function getBuildDefaults(EntityInterface $entity, $view_mode) {
    $build = parent::getBuildDefaults($entity, $view_mode);

    switch ($view_mode) {
      case 'table':
        $build['#theme'] = 'bibcite_reference_table';
        break;
    }

    return $build;
  }

and of course because bibcite_entity module do not implement a theme for bibcite_reference entity and do not provide the corresponding template.

Remaining tasks

- Agreed on the fix
- Write a pacth

User interface changes

None

API changes

None

Data model changes

None

CommentFileSizeAuthor
#9 3013783-9.patch3.86 KBflocondetoile

Comments

flocondetoile created an issue. See original summary.

flocondetoile’s picture

Issue summary: View changes

Looks like the issue is from the ReferenceViewBuilder

protected function getBuildDefaults(EntityInterface $entity, $view_mode) {
    $build = parent::getBuildDefaults($entity, $view_mode);

    switch ($view_mode) {
      case 'table':
        $build['#theme'] = 'bibcite_reference_table';
        break;
    }

    return $build;
  }
flocondetoile’s picture

Issue summary: View changes
flocondetoile’s picture

Title: Reference entity can not be rendered in another view mode » Provide a template for Reference entity to facilitate theming
Issue summary: View changes

Sorry. it was my fault. Reference are well rendered in another view mode.
But without a generic template, fields are rendered field by field. We could improve this?

Retitling the issue.

flocondetoile’s picture

Issue summary: View changes

  • antongp committed c554a53 on 8.x-1.x
    Issue #3013783 by flocondetoile: Provide a template for Reference entity...
antongp’s picture

Hello @flocondetoile.

Many thanks for your issue, it's really important addition! Template for reference entities has been added. Also number of template file name suggestions has been added, very similar to nodes. There is definitely a space for improvements as well as for other entity types provided by the module - they'll be delivered closer to beta1 (nearest target is alpha8), so this commit is more quick fix than complete change. Hope this works for the moment. Feel free to post your improvements and other features suggestions.

Thanks!

antongp’s picture

Category: Bug report » Feature request
Priority: Normal » Major
flocondetoile’s picture

StatusFileSize
new3.86 KB

Thanks. That was quick :-)

I would suggest now than we have a template for bibcite_reference entities to simplify the module and so remove the custom theme implementation bibcite_reference_table and use instead simply the view mode suggestion bibcite_reference__table ?

Also, it would be nice to use a more semantic html element for bibcite entities.
The article element seems perfect (source: https://www.w3.org/TR/html5/sections.html#the-article-element).

The article element represents a complete, or self-contained, composition in a document, page, application, or site. This could be a magazine, newspaper, technical or scholarly article, an essay or report, a blog or other social media post.

The patch attached add these suggestions.

antongp’s picture

Let's continue discussion of other possible improvements within #3015616: Improve theming of Reference, Contributor and Keyword entities, suggested in #9 changes are far from the original request :)
I listed some of possible improvements in the new issue, feel free to suggest more. I also like the idea of utilizing "base hook" for the table theming.

Listed improvements will be implemented after alpha8 is released. Theming changes and markup changes may be a breaking changes for some usages which we'd like to avoid within alpha8. Actually, adding template for reference entity and adding div wrapper in result may also affect appearance in some usages, but I believe it's a rare case.

Thanks!

antongp’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

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