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
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | 3013783-9.patch | 3.86 KB | flocondetoile |
Comments
Comment #2
flocondetoileLooks like the issue is from the ReferenceViewBuilder
Comment #3
flocondetoileComment #4
flocondetoileSorry. 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.
Comment #5
flocondetoileComment #7
antongp commentedHello @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!
Comment #8
antongp commentedComment #9
flocondetoileThanks. 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 patch attached add these suggestions.
Comment #10
antongp commentedLet'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!
Comment #11
antongp commented