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

ralf.strobel’s picture

Here is the closest to a solution that was found in the DS issue:

So, after some digging it's _field_info_prepare_extra_fields() which sets extra fields to be displayed by default. Even when not using DS, you'd be forced to disable them as well.

So it's either up to core to change this behavior or eva can also implement the alter hook to disable the extra field by default, that's not up to me.

ralf.strobel’s picture

Title: Field visibility status not relyable when using Display Suite » Hide newly added fields by default (prevent infinite loops)
Category: bug » feature

I'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.

mkadin’s picture

I 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?

mkadin’s picture

Status: Active » Closed (won't fix)

Again, 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.

jrao’s picture

Status: Closed (won't fix) » Active

How 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.

jrao’s picture

Issue summary: View changes

Fit introduction to new issue title.

tim.plunkett’s picture

Version: 7.x-1.1 » 7.x-1.x-dev
Assigned: Unassigned » tim.plunkett
Category: Feature request » Task
Issue summary: View changes
Priority: Major » Critical
Related issues: +#1256368: Add 'visible' key to hook_field_extra_fields()

We 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.

tim.plunkett’s picture

Status: Active » Postponed

Postponing for now.

Anonymous’s picture

Figured 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.

bburg’s picture

For 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.

geek-merlin’s picture

Title: Hide newly added fields by default (prevent infinite loops) » Prevent disabled fields from being rendered (performance)
Priority: Critical » Major

Updating 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.

Alan D.’s picture

Just 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()

  foreach ($views as $info) {
    $longname = $info['name'] . '_' . $info['display'];
    if (isset($fields[$longname]) && $fields[$longname]['visible']) {
      $build[$longname] = array(
        '#theme' => 'eva_results',
        '#weight' => $fields[$longname]['weight'],
      );
      $build[$longname . '_form'] = array(
        '#theme' => 'eva_exposed_form',
        '#weight' => $fields[$longname]['weight'] - 0.001,
      );
    }
  }

Implications with caching?

frob’s picture

I don't understand this reasoning.

I 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.

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?