Hello
Some times we are using if else to get end value.

if- Good --- $entity_field[0]['value'] = number_format($t,2);
else - NG ---$entity_field[0]['value'] = "";

The problem is $entity_field[0]['value'] = "";
still show the label. I had test ver 1.0 &1.1 0&dev
also get the label show, even the value empty.

How to fix that? or what I'm missing?
Thanks

Comments

chansionjoe created an issue. See original summary.

chansionjoe’s picture

StatusFileSize
new10.88 KB

IV Item #1 have value

QTY - Decimal filed - display(value&label) ; price - computed field - display(value&label)

IV Item #2 no value

QTY - Decimal filed - none display(value&label) ; price - computed field - I want to none display (value&label)

ram4nd’s picture

Title: empty value still shwo label » Empty value still shows label
hugronaphor’s picture

Just define $entity_field = NULL; before trying to populate with values.

colan’s picture

Version: 7.x-1.1 » 8.x-2.x-dev
Related issues: +#1928178: Hide field when output is empty (and DB is not used for storage)

As I just discovered, this is still a problem in D8, even if NULL is returned. Let's fix it there first.

I think the D7 problem was fixed in #1928178: Hide field when output is empty (and DB is not used for storage). We should probably try porting code from there.

colan’s picture

Status: Active » Needs review
StatusFileSize
new3.38 KB

isEmpty() was simply returning FALSE. With this patch, the computations are actually run to determine if the values are empty or not.

The D7 code wasn't helpful at all because it's procedural, not object-oriented.

I'm not crazy about having this code block in 3 places (for strings, integers and decimals), but it seemed less confusing than introducing yet another trait for classes that override executeCode():

  /**
   * {@inheritdoc}
   */
  protected function getRawResult() {
    return parent::executeCode();
  }
colan’s picture

StatusFileSize
new4.27 KB
new3.04 KB

I wasn't comfortable with the duplicated code so I finally added the new trait.

tonypaulbarker’s picture

This is still a problem. isEmpty is just set to FALSE regardless of calculations.

I need to set null values so I can average later with aggregation in views and not have incomplete fields scoring zero and bringing down the average.

#7 works well for me.

  • colan committed 86cdd99 on 3.x
    Issue #2663140 by colan: Check for empty values by running computations.
    
colan’s picture

Version: 8.x-2.x-dev » 3.x-dev
Status: Needs review » Fixed

Thanks for the review!

Status: Fixed » Closed (fixed)

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