Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
When view returns nothing and empty text is not field result of rendering viewfield should be empty.
But in realy it returns divs that cover view. like
I create patch fix this problem.
Comment | File | Size | Author |
---|---|---|---|
#64 | viewfield-empty-views-477244-64.patch | 1.75 KB | jerdavis |
#60 | viewfield-eng.jpg | 194.38 KB | VasyOK |
#56 | viewfield-empty-views-477244-56.patch | 6.57 KB | frjo |
#55 | viewfield-empty-views-477244-55.patch | 6.28 KB | Syndz |
#52 | viewfield-empty-views-477244-51.patch | 6.13 KB | morbiD |
Comments
Comment #1
Darren OhPatch doesn't apply to current code.
Comment #2
Darren OhI believe this was fixed in CVS commit 214936.
Comment #3
Anonymous (not verified) CreditAttribution: Anonymous commentedI'm still seeing this with the June 17th dev version.
Comment #4
igor.ro CreditAttribution: igor.ro commentedI think we could not solve this problem while we are using view embed method to show view field.
Comment #5
muhleder CreditAttribution: muhleder commentedIt's possible to override this behaviour, so that empty viewfields do not display (like other cck fields).
This is the code I'm using in my template.php to override the theme, would be nice if this could make it into the module so we don't have to fix this. I'll put a patch together if there's interest in testing it.
Comment #6
japanitrat CreditAttribution: japanitrat commentedTaking the code above into the module, the following patch should fix the problem
Comment #7
japanitrat CreditAttribution: japanitrat commentederr, wrong patch. here is the correct one
Comment #8
japanitrat CreditAttribution: japanitrat commentedgood lord, i really need some sleep ...
(yes this is the correct patch now)
Comment #9
sunNot sure whether I agree with this. Why would we want to invoke the view's preview if we want to embed it?
Powered by Dreditor.
Comment #10
muhleder CreditAttribution: muhleder commentedThat piece of code
$output = $view->preview($display, $view_args);
comes from the Views function.This patch basically replaces a call to views_embed_view with the code from views_embed_view, but includes a test on the number of results and returns nothing if number of results is 0.
views_embed_view otherwise returns an empty div tag (from memory), which cck then interprets as a non-empty field.
Here's the code from Views so you don't have to hunt it down
Comment #11
sunThanks for reporting, reviewing, and testing! Committed attached patch.
A new development snapshot will be available within the next 12 hours. This improvement will be available in the next official release.
Comment #13
fraweg CreditAttribution: fraweg commentedHello,
is there also a solution for drupal7?
Best regards
Frank
Comment #14
dropfen CreditAttribution: dropfen commentedBug is still present in 7.x !!!
Comment #15
SilviuChingaru CreditAttribution: SilviuChingaru commentedIf we approach this way, it needs a lot of code cleanup, but for an initial patch I'd like to show where the problem is at first.
Comment #16
SilviuChingaru CreditAttribution: SilviuChingaru commentedCleaned up unnecessary code.
Comment #17
dman CreditAttribution: dman commented+1 for me.
Seems to have fixed the problem on my limited testing.
Comment #18
mel-miller CreditAttribution: mel-miller commentedPatch in #16 works for me. Thanks.
Comment #19
mvwensen CreditAttribution: mvwensen commentedPatch in #16 works as a charm! Patch applied to version 7.x-2.0
Comment #20
holdmann CreditAttribution: holdmann commentedSome bug occured when applying patch #16.
Steps to reproduce:
1. Create view of single node type (e.g. articles) with contextual filter [Content:nid] from url, with option exclude argument from view result. Set style plugin as rendered entity, for example teasers;
2. Create viewfield field in node type, and attach view described above to it;
3. Remove viewfield display on teaser view mode. So this field shows only on full content.
That's all. Now there is WSOD with message "allowed memory exceed...". On my server allowed memory size is about 2Gb, so it looks like memory leaks.
I guess there is infinite loop - on hook_field_prepare_view(), but haven't chance to proove it.
Any ideas?
Comment #21
sashkernel CreditAttribution: sashkernel commentedI'm using 7.x-2.0 and FieldGroup module. View field still returns something that causes FieldGroup to show the tab, even though it's supposed to invisible, because View returns nothing.
Any Idea how this can be fixed?
Comment #22
SilviuChingaru CreditAttribution: SilviuChingaru commented@sashkernel please provide the viewfield output (at least html one) to figure out where problem is. I think your view is still outputing something. A view export will be also useful.
Comment #23
SilviuChingaru CreditAttribution: SilviuChingaru commentedComment #24
sashkernel CreditAttribution: sashkernel commentedI've noticed that in Field Group module where when nothing is returned field group does not appear. This is the only place I see something returned.
This could well be related to the issue where I'm trying to pass an argument to the view through the view field and it's not working properly (https://drupal.org/node/1350916)
Here's HTML output I'm getting.
Basically I'm not getting anything there, while in other viewfields that display view without contextual filters display correctly or simply disappear when view is blank.
Comment #25
SilviuChingaru CreditAttribution: SilviuChingaru commented- Did you applied the patch from #16???
- Did you cleared cache and views cache?
Comment #26
sashkernel CreditAttribution: sashkernel commented#16 fixed it. Thank you fiftyz.
Is this going to be ported into the next version?
Comment #27
sashkernel CreditAttribution: sashkernel commentedContinuing into this issue but for "Role Based view permissions".
I noticed that for views, which are rendering output only for particular role, "ViewField" does not work either. "Field Group" module detects that there is some output from "ViewField". And user who is not part of the permitted role sees the field group tab with blank output.
Pretty much same issue, but with role based view permissions.
Comment #28
jferjan CreditAttribution: jferjan commentedsubscribing
Comment #29
rjacobs CreditAttribution: rjacobs commentedThis was marked "Postponed (maintainer needs more info)" in #22, but it looks like the info requested was provided and deemed unrelated. I hope to not be stepping on anyone's toes, but I just wanted to update the status to reflect the current situation as best I can.
This was previously RTBC, but I'm not sure if if should be moved back to that status due to the concern raised in #20. Moving back to "Needs Review" for now.
For what it's worth we have been using this patch in production for months now without issues.
Comment #30
rjacobs CreditAttribution: rjacobs commentedHiding more outdated files.
Comment #31
keva CreditAttribution: keva commentedThe patch in #16 works on the 2013-Oct-19 dev version.
Not using it with FieldGroup, so can't speak for that issue.
Comment #32
bfr CreditAttribution: bfr commentedI get
Fatal error: Call to undefined method stdClass::preview() in XXX/sites/all/modules/contrib/viewfield/viewfield.module on line 120
when i try to move Views cache to Redis with this patch applied. I don't think the class should be stdClass, maybe it's getting broken or null response when trying to load the view?
Comment #33
bfr CreditAttribution: bfr commentedSeems like
$view = views_get_view($view_name);
sometimes returns null when Redis is used, and then
$view->override_path = current_path();
turns it into a stdClass object. Then ->preview() naturally crashes.
Checking for correct class seems to fix it:
but does this have side effects?
Comment #34
nasi CreditAttribution: nasi commented#16 works for me, patched against 7.x-2.0 (also not using field group).
Comment #35
sgurlt CreditAttribution: sgurlt commentedApplied patch #16 against latest dev, looks good :)
Comment #36
seworthi CreditAttribution: seworthi at Estrella Mountain Community College commentedWorks great.
Comment #37
sgurlt CreditAttribution: sgurlt commentedBe careful with that patch, I just found out that when you are using rendered entities in a view and including a pager, this patch will break your pagers completly. I will investigate in this.
Comment #38
sgurlt CreditAttribution: sgurlt at Bright Solutions GmbH commentedOk i rerolled patch #16.
I had two issues with it:
1. When a repeatable imagefield (with for example max repeat set to 5) was displayed inside the view, the view results wasnt empty even if no image was added at all. I improved the view result checking.
2. The second thing was a bit more tricky.
Imagine you have a viewfield attached to the user entity, this view field always shows (view-1). This (view-1) has a pager.
Then you have another view (view-2) which shows all users as rendered entites and you want to add a pager to this view. The pager will not be shown at all!
The problem is that when loading the rendered entity, the view from the user entity is also loaded, the pager ID of (view-1) is set globally and if the pager is currently not shown in (view-1), it is also will not be shown on (view-2). To fix that we simply can change the pager ID of (view-1) or (view-2), this can be done when editing the pager, just set it to another ID then 0.
I added a comment for this inside the README.txt
Cheers
Comment #39
AaronBaumanAttached patch did not apply cleanly for me, does not have appropriate diff context.
Here's a re-name, re-roll
Comment #40
sgurlt CreditAttribution: sgurlt at Bright Solutions GmbH commentedPlease review the patch also functionally.
Comment #41
lquessenberry CreditAttribution: lquessenberry as a volunteer and commented#39 Patched properly with no errors for me, but I was using the patch to solve a problem in another issue which said that #16 would be the solution. Can anyone confirm that they are using a viewfield with Search API?
https://www.drupal.org/node/1705874
If so, can you determine that the above patch #39 worked for you as a better alternative to #16 (which wouldn't patch for me properly)?
Thanks. Just to confirm, #39 patched for me just fine.
Thanks,
Lee
Comment #42
AaronBauman#39 is a re-roll of #16.
They should be considered equivalent.
Comment #43
lquessenberry CreditAttribution: lquessenberry as a volunteer and commentedThanks! Now I just have to see what I am missing on getting the field to show up in Search API for an index.
Comment #44
Anybody#39 solves the problem perfectly for me and removes the empty div without side effects so far. +1 for RTBC!
Comment #45
thomas.frobieterI agree, #39 is working fine. +1 for RTBC
Comment #46
roflcopterDorrie CreditAttribution: roflcopterDorrie commented#39 works for me as well :)Actually I am getting a fatal error when the view tries to render.
Fatal error: Unsupported operand types
on line 1415 of node.module.I have workbench moderation, views and viewfield working together, not sure if that is relevant or not.
Only happens when I apply the patch.
Comment #47
Anybody@roflcopterDorrie could you please send a debug backtrace to find out what happens technically? Otherwise it will be hard to solve your problem.
We really have to take this issue forward. It's imporant and too old to stay open furthermore.
Comment #48
jsantander CreditAttribution: jsantander as a volunteer commentedI've applied patch #36 cleanly
However, it seems to be detecting a non-empty view with only a "title" field as empty.
Looking at the code, I'm not sure about the logic of this code:
For one thing, the first if is wrong... it has the < 2 inside the count():
if (count($view->result) < 2) {
if (count($view->result < 2)) {
Then, I don't know much about the view's api, but my guess is that $view->result contains an array with one element for each item returned by the view.
My guess is that the code tries to prevent a case where one row is returned, but with all its fields set to empty.... but (once fixed the above mistake) will consider any >2 result empty.
Comment #49
jsantander CreditAttribution: jsantander as a volunteer commentedWell, after some investigation, this is my version of the #39 patch.
Basically I've modified the code above to be:
The changes are:
Comment #50
jmato CreditAttribution: jmato commented#49 works for me, but only with the 1st and 2nd fixes, the 3rd fix crash with the following unrecoverable error: "Can't use method return value in write context". #39 hide the field rather if the view was empty or not. Using 2015-Apr-09 dev version.
Comment #51
morbiD CreditAttribution: morbiD commentedThe patch in #49 is broken and fails to apply to either a clean 7.x-2.x, or to 7.x-2.x with #39 already applied.
Looks like @jsantander did a reverse diff or something, so the patch is actually trying to remove his code rather than apply it...
Edit: Applying the patch in reverse works, but adds whitespace errors in two places. Also, the last line of the patch adds a double semicolon after the return.
Edit 2: I get the same error as #50. It seems you can't use
empty()
directly on the return fromview_handler_field::get_value()
. It must be assigned to a variable first, which can then be passed toempty()
.Comment #52
morbiD CreditAttribution: morbiD commentedThis patch simply fixes #49 so it actually applies properly and doesn't produce fatal errors on PHP < 5.5.
I also reworded some of the documentation added by the patch since it wasn't clear to me what it actually meant until I went back and read #38.
The patch seems to resolve the issue for me but I can't comment on how well it works with other modules like Field Group.
I think the @todo items in the patch are probably best left for separate issues so I haven't bothered to address them here.
Comment #54
Syndz CreditAttribution: Syndz at Nedbase commentedI've noticed that the above patches only work for field based views.
This is because there's a check if field contain values, though, a view that renders entities, does not have field values.
I've added some extra logic so that only field values are being checked if the field row plugin is being used.
Comment #55
Syndz CreditAttribution: Syndz at Nedbase commentedThe patch in #54 is generating a lot of notices, here's a new patch.
Comment #56
frjo CreditAttribution: frjo commentedAdded check for empty view that uses entity display to #55.
Other than that #55 worked well for me.
Comment #57
Heorhi Lazarevich CreditAttribution: Heorhi Lazarevich commentedPatch #56 works for me for fields and entity display with Vewfield version 7.x-2.1
Comment #58
jatorresdev CreditAttribution: jatorresdev commentedPatch #56 works for me. Use display suite with Viewfield 7.x-2.1, please add it to the next version
Comment #59
jimafisk CreditAttribution: jimafisk at Jantcu commentedPatch #56 works great! Applies cleanly to 7.x-2.1.
Comment #60
VasyOK CreditAttribution: VasyOK commentedPatch worked only if field NID exist in view. Even if this field is not needed
Comment #61
drupalgin CreditAttribution: drupalgin as a volunteer commentedPatch #56 worked for me.
Comment #62
anneeasterling CreditAttribution: anneeasterling as a volunteer commentedIn order to get this to work on our site, this code:
needed to be changed to
Can someone please verify that the changed version was the intent?
Thanks!
Comment #63
jerdavisThis hook is not the correct place to build the view and check for results. This hook is fired regardless of whether or not the field is to be displayed for a given view mode. The end result is if your view is going to output a set of teasers, and one of the nodes being output as a teaser has a viewfield - this code is executed and munges with the node content producing a fatal error, even if the viewfield on the teaser within the parent view was never going to be displayed.
I'd like to see this reworked to not rely on style plugins. At this point in code execution checking $view->result should be sufficient. Checking each style plugin isn't sustainable as you'd need to account for all possible style plugins. As it is, this code only checks fields and entity, which in D7 would be node for full content.
Comment #64
jerdavisAttaching a patch that adds a post_render callback to the top-level elements array. This callback iterates over any element children and checks their referenced view for results or an empty result behavior. If any of the child views have content the $content is returned. If they are all empty, NULL is returned.
Tested this against both field and content display styles. This update will be committed to 7.x-3.x today. I'll defer committing to 7.x-2.x pending further feedback.
Comment #65
jerdavisComment #66
jerdavisComment #68
.bert CreditAttribution: .bert commentedI can confirm that the patch in #64 applied cleanly to version 7.x-2.1 and resolved the issue in our use case.
We are also using field_group in our setup and there appears to be no issues.
Comment #70
jerdavisThanks for the review! Pushed to 7.x-2.x to be included in the next release.