I experienced this problem most severely in combination with Display Suite. But it also leads to a more general issue (see comment #2).
When EVA adds a new field through hook_field_extra_fields(), it is placed in the "disabled" region of the entity in DS, and so it is not being shown in any view modes except those where you manually enable it.
The problem is that even though placed in "disabled", field_extra_fields_get_display() still reports "visible" = TRUE. As a result, the view is still being executed whenever the entity is shown (even for every teaser!). Luckily you can resolve this by moving the field to a different region and back.
Before I figured this out I was struggling with very slow page loads and even an infinite loop, because I had added a view to an entity that included itself (as a teaser) in the output.
See the DS issue here: #1296596: Extra fields reported "visible" at first, while placed in "disabled" region
Comments
Comment #1
ralf.strobel CreditAttribution: ralf.strobel commentedHere is the closest to a solution that was found in the DS issue:
Comment #2
ralf.strobel CreditAttribution: ralf.strobel commentedI'm changing this into a feature request. Independent from the problem described above, I think it would be a good idea to have new fields hidden by default for two reasons:
1) Even if you don't use DS, you could still accidentally create an infinite loop if you add a view field to an entity which displays the entity itself. This could happen by accident, but it's also a realistic use case. For instance you may want to add a "sibling posts" list to the full view of an entity, which displays all posts of the same type (including itself) as a list of teasers. Since the new field would also be visible in the teaser view mode by default, you have your infinite list.
2) It's probably more common to add a new field to only one specific view mode of an entity than to add it to all of them. So currently you would have to go and hide the field in all other view modes instead of just switching it on in the one you want.
Comment #3
mkadin CreditAttribution: mkadin commentedI don't necessarily agree that this is a good idea. For a user not using DS, your assumption that a newly created EVA view might only be wanted in a particular view mode doesn't really stand. My feeling is that most users want to configure their new view and then have it show up immediately. Factor in the caching issues that we've been seeing and people might get quite frustrated trying to get their new EVA view to actually show up.
Is there some way we can avoid the problems with infinie loops without setting the field to be disabled by default? Or is it up to site builders to avoid infinite loops?
Comment #4
mkadin CreditAttribution: mkadin commentedAgain, I'm not huge on the idea of adding another step to making an EVA view actually show up. If someone has a solution for avoiding infinite loops that doesn't involve hiding a new EVA view by default, please reopen this issue.
Comment #5
jrao CreditAttribution: jrao commentedHow about making EVA field visible only at default view mode initially? I think this is how other fields behave. Also if I have 10 view modes, adding a new EVA field means I had to turn it off in 9 of them, it's a lot of unnecessary work.
Comment #5.0
jrao CreditAttribution: jrao commentedFit introduction to new issue title.
Comment #6
tim.plunkettWe absolutely want to do this! But we can't yet.
#1256368: Add 'visible' key to hook_field_extra_fields() is the core issue that blocks this.
Comment #7
tim.plunkettPostponing for now.
Comment #8
Anonymous (not verified) CreditAttribution: Anonymous commentedFigured I'd report another very strange occurrence. When I have a taxonomy term page that I am placing a regular block view on via context an infinite loop occurs if I have EVA enabled, regardless of the fact that I am not even using EVA. Once disabling this module, everything works as expected.
Comment #9
bburgFor me, this issue manifested itself by preventing pagers on my search pages from showing. Apparently Drupal treats a pager as a global variable, which were reset by the views attached to some of the entities that were appearing in search results. Global variables and re-entrant rendering don't get along. Just dropping a note here to improve the search-ability of this issue. Following the suggestions in #1296596: Extra fields reported "visible" at first, while placed in "disabled" region resolves this issue, although it's an annoying step.
Comment #10
geek-merlinUpdating issue title and adjusting prio.
This actually is a core issue: #1256368: Add 'visible' key to hook_field_extra_fields()
More info in the DS issue: #1296596: Extra fields reported "visible" at first, while placed in "disabled" region
Workarounds:
* Manually enable and then disable a field
* Patch from the core issue: #1256368: Add 'visible' key to hook_field_extra_fields()
* Workaround from the core issue: #1256368-105: Add 'visible' key to hook_field_extra_fields()
Postponing to leave it open until the core issue is fixed.
Comment #11
Alan D. CreditAttribution: Alan D. commentedJust had #2289601: View should only be rendered when needed (no patch) marked as a duplicate, but that was to simply defer executing the view until it was rendered.
This would also be an easy fix to stop DS from executing non-rendered fields as per the original request and to reduce the possibility of comment #2.
i.e. couple new theming functions and switch to using these rather than executing a full view build & render via eva_entity_view_alter()
Implications with caching?
Comment #12
frobI don't understand this reasoning.
I was just hit by the pager issue. In my case, we had to create a couple more EVAs with the addition of a new content type. These are displayed on content types that have around 7 view modes. Each EVA will have to be enabled (because DS) and then disabled in all but the full view mode. Even in the full view mode we do not want the EVA displayed where-ever it wants. We want to tell it where to go.
So then, why not just have it disabled by default? Is #1256368: Add 'visible' key to hook_field_extra_fields() really a blocker? It seems like this should be able to be done pragmatically when adding a new EVA by just setting the visibility programmatically after creating the EVA. Is there no hook in views that allows for an operation after saving a view?