In the 2010-Oct-13 release of 6.x-3.x-dev, if you use the "Rewrite the output of this field" option and put in some text and also tell the field to "hide if empty", the text will still display. This worked properly in the 2010-10-11 release.

For example, I'm creating a list of actors and characters and each entry can have up to 5 actors/characters. I'm rewriting the output of the various Actor and Character field output so that for the fields Actor2 through Actor5 all have a " | " in front of the field replacement pattern, and there are parentheses surrounding all Character field output. This way all the fields would have the proper "formatting" when output regardless of how many actor/character entries there are per record. With this release, it creating output like this (if there are fields hidden if empty):
Actor1 (Character1) | () | () | () | ()
whereas prior releases would only display:
Actor1 (Character1)

Comments

HunterElliott’s picture

As an FYI, this issue still exists in version 6.x-3.x-dev dated 2010-10-15.

HunterElliott’s picture

To verify I had the right version when it last worked properly, I reloaded the 6.x-3.x-dev version that I said was released on 2010-10-11 and I was incorrect. It was released on 2010-09-30. Re-installing this previous version did restore the "hide if empty" routine to work properly.

HunterElliott’s picture

Is anyone able to determine whether or not this issue will be addressed in a future release?

dawehner’s picture

Status: Active » Postponed (maintainer needs more info)

can you try out git bisect to find the patch which caused this issue?

dawehner’s picture

HunterElliott’s picture

Sure. I've not used that before but I do have both a good and bad version of the 6.3.dev modules. Let me see what I can find.

HunterElliott’s picture

Dereine, I must admit to being a git about GIT. I wasn't able to figure it out. However, I was using another app to compare differences between files and wonder if any of the following could be part of the issue:

in handlers\views_handler_area_text.inc, line 20 has the following in the "good" version"
'#description' => $description,
whereas in the "bad" version it is not present.
Line 52 of the good file reads:
if (!$formats[$format]) {
whereas the corresponding line in the "bad" version (line 51) reads:
if (!isset($formats[$format])) {

-------------------------

in handlers\views_handler_field.inc in the "good" version starting at line 517 it reads:

  function render_text($alter) {
    $value = trim($this->last_render);
    if ($this->options['hide_empty'] && empty($value) && ($value !== 0 || $this->options['empty_zero'])) {
      return '';
    }

    if (!empty($alter['alter_text']) && $alter['text'] !== '') {
      $tokens = $this->get_render_tokens($alter);
      $value = $this->render_altered($alter, $tokens);
    }

whereas the "bad version seems to have some of the items "flipped" in terms of sequence.
The "bad" version of this file starting on line 517 reads:

  function render_text($alter) {
    $value = trim($this->last_render);

    if (!empty($alter['alter_text']) && $alter['text'] !== '') {
      $tokens = $this->get_render_tokens($alter);
      $value = $this->render_altered($alter, $tokens);
    }

    if ($this->options['hide_empty'] && empty($value) && ($value !== 0 || $this->options['empty_zero'])) {
      return '';
    }

Could the "flip/flop" of the IF statements be the issue?

zualas’s picture

@HunterElliott

Looks like you found the issue source. I flipped the two conditions back, and I don't have the issue anymore. Thanks!

HunterElliott’s picture

@zualas: Great to hear that a) I wasn't the only one with the problem, and 2) that I found the right code :)

Here's to hoping one of the maintainers actually sees this and can incorporate the fix!

esmerel’s picture

Assigned: Unassigned » dawehner
Status: Postponed (maintainer needs more info) » Active

@hunterelliott - I'm going to go ahead and assign this to dereine, but if you feel up to actually creating the patch yourself, I'm pretty sure he wouldn't mind a bit :)

HunterElliott’s picture

I'll work on getting a patch made asap. I'll grab the latest version of the module to compare and make sure it's not already been addressed.

HunterElliott’s picture

StatusFileSize
new835 bytes

Attached is my first ever attempt at a patch. I hope it's in the proper format, etc. Here are the contents of the patch file:

--- sites/all/modules/views/handlers/views_handler_field.inc	Thu Oct 14 18:08:24 2010
+++ sites/all/modules/views/handlers/views_handler_field.inc	Fri Aug 13 13:41:20 2010

@@ -516,16 +516,15 @@
    */
   function render_text($alter) {
     $value = trim($this->last_render);
+    if ($this->options['hide_empty'] && empty($value) && ($value !== 0 || $this->options['empty_zero'])) {
+      return '';
+    }
 
     if (!empty($alter['alter_text']) && $alter['text'] !== '') {
       $tokens = $this->get_render_tokens($alter);
       $value = $this->render_altered($alter, $tokens);
     }
 
-    if ($this->options['hide_empty'] && empty($value) && ($value !== 0 || $this->options['empty_zero'])) {
-      return '';
-    }
-
     if (!empty($alter['strip_tags'])) {
       $value = strip_tags($value);
     }
HunterElliott’s picture

So... did I create the patch properly?

bojanz’s picture

Status: Active » Needs review

The patch should be created from the views module root, not the drupal root (only core patches are created from drupal root).

Not sure about the fix though.
The change you are reverting was introduced in #936828: [token] empty text replacement does not work with values of zero that are formatted, so we need to satisfy both use cases here...

bojanz’s picture

Status: Needs review » Needs work
dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new787 bytes

Here is a fast rerole.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

In general it looks fine for me.

bojanz’s picture

Status: Reviewed & tested by the community » Needs review

What about my #14? (xjm's patch mentioned...)

dawehner’s picture

Status: Needs review » Needs work

Oh

dawehner’s picture

This might should be configurable, right?

gopherspidey’s picture

By the way this also affects the 7.x-3.0-alpha1. I was trying the rewrite the contents of the field with to display an img, but I only wanted the image to show up if the field was set. This was to let end users know that there was something there. I ended up creating a customer formatter in drupal 7 to get around this issue of rewriting the field output.

jindustry’s picture

I tried this patch and experienced strange behavior. Before the patch, I can rewrite a field but it's not hidden if empty. After the patch, it's hidden if empty but it doesn't get rewritten. Is anyone else getting this behavior? My view includes multiple node types, and some nodes do not contain the field at all.

rp7’s picture

subscribing. rewriting field output -> empty field doesn't hide.

rootdownmedia’s picture

+1 subscribe. Any workarounds in the meantime?

mcornes’s picture

Well spotted. This is still a problem in the latest v6 Views latest Dev I downloaded today dated the 21 Jan 2011. I manually added the patch into the mix and boom my "hide if empty"s began working, even when I was rewriting the field!

Thanks.

Can be seen working here, the results column needed hiding if empty, because the game hadn't been played yet, and rewriting if a score was there so I could link to the match report.

http://www.loreto.ac.uk/sportingfixtures

karljohann’s picture

This is still a problem in the Feb 5th dev release.

hatsch’s picture

i have the same problem. applying the patch from #16 helps, the field is not showing anymore if empty

although the "Empty Text" Field is not working yet.

xjm’s picture

Hm, tracking.

xjm’s picture

Re: #20, it does seem to me that it would need to be configurable... that, or do we need to evaluate zero values as a special case?

HunterElliott’s picture

Digging around in other issues regarding this same problem, I found a work around. I think it's a bit of a kludge as this feature should work as it did prior to the updates from October 2010 (IMO).

This "fix" is not intuitive (well, at least not to me). When you've gone in to the Rewriting section, click the "rewrite the output of this field" and put in your token like you always have. This is where it was not intuitive to me. Click the box next to "Output this field as a link" in the rewriting section. (Why would I click this when the option to output it as a link is towards the bottom of all the options?) Ignore all the other options here and just put something in the Prefix and Suffix sections. For me, it would be things like ( and ) or |. Then just do your regular "hide if empty" stuff.

laroccadahouse’s picture

code in #12 worked for me re: rewriting field output -> hide empty field.

riyasmtpm’s picture

hi Tim all
Somebody help me with my requirement pls...I want to allow my users to choose their front page and save the selection with their profile.Next time they log in they have to see only the terms which they are selected before.

Exmple: My site(job portal) having 3 vocabularies

1.City
--New delhi
--Banglore

2.Experience
--1 year
--2year

3.Technology
--PHP
--Java

Here i need logged in users to choose the terms

for example a person from Banglore with one year experience in PHP Will have to choose these terms in his front page.
Pls help as soon as possible and advance thanks for your precious time.

vikramy’s picture

Subscribing

johnpitcairn’s picture

Ack. Subscribe.

fletch11’s picture

... me too

jonathanmd’s picture

subscribing

adooo’s picture

subscribing

dawehner’s picture

Status: Needs work » Fixed

This is a duplicate of #1020540: Add a "Hide Rewriting if field is empty" option On this issue is already a patch.

dawehner’s picture

Status: Fixed » Closed (duplicate)

That's the wrong status.