I have a multivalue text field and have filled it with value. if i try to get this value the return value is empty.

The genereated getter / setter methods:

  /**
   * Sets field_validation_tokens
   *
   * @param $value
   *
   * @return $this
   */
  public function setValidationTokens($value, $format = NULL) {
    $this->setText('field_validation_tokens', $value, $format);
    return $this;
  }

  /**
   * Retrieves field_validation_tokens
   *
   * @return mixed
   */
  public function getValidationTokens($format = WdEntityWrapper::FORMAT_DEFAULT, $markup_format = NULL) {
    return $this->getText('field_validation_tokens', $format, $markup_format);
  }
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

fox_01 created an issue. See original summary.

fox_01’s picture

if i switch the field to single value then it returns the correct value

zengenuity’s picture

Please test this patch.

You will need to regenerate the getters and setters in your bundle classes to test. Just delete those functions and run the drush command again.

Please let me know if this works for you.

zengenuity’s picture

Status: Active » Needs review
fox_01’s picture

Status: Needs review » Reviewed & tested by the community

#3 Works.

Thanks for that quick response

  • zengenuity committed 423a3d8 on 7.x-1.x
    Issue #2785339 by zengenuity: multivalue text fields returned empty
    
zengenuity’s picture

Status: Reviewed & tested by the community » Fixed

#3 committed.

fox_01’s picture

Status: Fixed » Needs work

I have found a new issue from the patch.

If i have a single value text field and do a drush wrap on a new entity i get generated the function "$this->setTextMultiple" instead of "$this->setText" in the getter / setter method. This leads to an error in the foreach loop. If i manually modify the line $this->setTextMultiple to $this->setTextMultiple then it works.

zengenuity’s picture

I tested the single-value text field scenario as when I was making the patch, and it was working for me. Can you give me more details about the field you are having trouble with? Text or Text Long? Filtered or Plain Text? Anything else unusual with it?

zengenuity’s picture

Oh wait, are you saying that you're setting a single value on a multiple value field? In that case, you need to be passing an array. Wrap the value in an array when it's a multi-value field.

fox_01’s picture

Its a normal plain text field single value named street.

What i was trying to do is this

$config_wrap->getStreet();

I am getting the warning

Warning: Invalid argument supplied for foreach() in WdEntityWrapper->getTextMultiple() (line 133 of /sites/all/modules/wrappers_delight/includes/WdEntityWrapper.php).

I have found that the getter has the wrong function

  public function getStreet($format = WdEntityWrapper::FORMAT_DEFAULT, $markup_format = NULL) {
    return $this->getTextMultiple('field_street', $format, $markup_format);
  }

If i mody this line to the following its working

  public function getStreet($format = WdEntityWrapper::FORMAT_DEFAULT, $markup_format = NULL) {
    return $this->getText('field_street', $format, $markup_format);
  }
zengenuity’s picture

The patch is the problem. It doesn't have the new files I added.

I've committed the changes. Can you try it with the dev version? Let me know if it works correctly then.

fox_01’s picture

Status: Needs work » Fixed

works now as you described

Status: Fixed » Closed (fixed)

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