There is a wrong created function when you have a entity_reference multivalue field. The set part is correct but the get function only works if there is one entity referenced

public function setCommissions($value) {
    if (is_array($value)) {
      foreach ($value as $i => $v) {
        if ($v instanceof WdAffiliateMlmWrapper) {
          $value[$i] = $v->value();
        }
      }
    }
    else {
      if ($value instanceof WdAffiliateMlmWrapper) {
        $value = $value->value();
      }
    }

    $this->set('field_commissions', $value);
    return $this;
  }

  /**
   * Retrieves field_commissions
   *
   * @return CommisionsAffiliateMlmWrapper
   */
  public function getCommissions() {
    $value = $this->get('field_commissions');
    if (!empty($value)) {
      $value = new CommisionsAffiliateMlmWrapper($value);
    }
    return $value;
  }

Comments

fox_01 created an issue. See original summary.

fox_01’s picture

I modified the function to this which is working

public function getCommissions() {
    $value = $this->get('field_commissions');
    if (!empty($value)) {
      if(!is_array($value)){
        $value = new CommisionsAffiliateMlmWrapper($value);
      }
      else{
        foreach($value as $key => $entity){
          $value[$key] = new CommisionsAffiliateMlmWrapper($entity);
        }
      }
    }
    return $value;
  }
fox_01’s picture

can this be integrated into a release?

zengenuity’s picture

Did you change your cardinality on this field? Did it used to be a single value? If so, you need to clear this function and regenerate. When I test things from scratch, it works fine with multi-valued entityreference fields.

zengenuity’s picture

Status: Active » Closed (works as designed)