EVA displays are triggering regions to display even when they are empty because they still output a renderable array.

I've added an option to hide the output if the view is empty, like there is on the Block display. This gets checked in hook_entity_view() before the call to render.

Comments

dkosbob created an issue. See original summary.

dkosbob’s picture

StatusFileSize
new2.93 KB
ahebrank’s picture

This makes sense to me -- certainly used to frustrate me during theming.

Can you move the visibility check (if ($this->outputIsEmpty() && $this->getOption('eva_hide_empty') && empty($this->view->style_plugin->definition['even empty']))) into a new handler method and call that method where needed from the handler and eva.module?

Looking through the API, !$this->view->getStyle()->evenEmpty() might be a safer way to get the style plugin setting.

Seeking feedback/testing from others.

dkosbob’s picture

StatusFileSize
new2.23 KB

Yes, here is a new patch. I've added a buildRenderable() method to the Eva class, and am doing the check there. It seems to be working as intended in my dev environment, but I'd appreciate some other eyes on this.

aaronbauman’s picture

Is it a problem that parent::buildRenderable() doesn't get called?
Looks like \Drupal\views\Plugin\views\display\DisplayPluginBase::buildRenderable() adds cache metadata.
How will this change impact views' caching and overall performance?

Calling \Drupal\views\ViewExecutable::execute() during buildRenderable() doesn't seem like a great idea either.
I think your first instinct to check during \Drupal\eva\Plugin\views\display\Eva::execute() was better

aaronbauman’s picture

StatusFileSize
new2.64 KB
new1.23 KB

This patch:
- Adds protected method "shouldDisplayOutput()" to calculate whether to return a renderable
- Moves the call back into execute(), ditching the buildRenderable() override

dkosbob’s picture

This looks good to me and makes sense. I'm using patch #6 on a pre-production site and it's working well.

aaronbauman’s picture

Bumping this

wrd’s picture

The option is now available and configurable, but I'm still getting the empty markup output. In my case, I'm placing the EVA in a Layout Builder region.

brandonratz’s picture

I can configure the option but same output in container.html.twig which triggers a field_group to display. Not yet working.

hanoii’s picture

StatusFileSize
new0 bytes
new3.92 KB

I think I fixed this, as we're also having the issue in which there was something being rendered.

I basically am doing the same thing as ViewsBlock.php does when the field is being added to the entity (outside of the view).

I also refactor the plugin patch slightly. I removed the method and copy over what core's block plugin does. Easier to diff and to keep upstream changes. The new method can be done on a separate issue/commit if really desired. Also changing the negation of the conditions as per the above.

hanoii’s picture

I'd also move the option to the Other section (exactly as block) but in a way made more sense to have it there.

hanoii’s picture

brandonratz’s picture

#11 works as expected in our use cases.

aaronbauman’s picture

bumping again

dries arnolds’s picture

This was my first time using EVA in the D8 version and I was surprised that it didn't work the same way as the D7 version.

Tested the patch in #11 and it works as expected. Can we get this committed?

aaronbauman’s picture

bump

pakmanlh’s picture

Status: Needs review » Reviewed & tested by the community

I can confirm the #11 patch works using the 3.0 version and Drupal 10 versions too.

  • hanoii authored 2f025fd0 on 3.0.x
    Issue #3083993 by dkosbob, hanoii, AaronBauman: Hide output if empty...
ahebrank’s picture

Version: 8.x-2.x-dev » 3.0.x-dev
Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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

anybody’s picture

FYI: Looks like the default should have been TRUE to match the previous behavior and hide the view entirely, if empty... we were wondering why EVA views that were not appearing before, suddenly appeared...

Just to let others know, running into this.