You are here

public function YamlFormSubmission::toArray in YAML Form 8

Gets an array of all property values.

Return value

mixed[] An array of property values, keyed by property name.

Overrides ContentEntityBase::toArray

File

src/Entity/YamlFormSubmission.php, line 652

Class

YamlFormSubmission
Defines the YamlFormSubmission entity.

Namespace

Drupal\yamlform\Entity

Code

public function toArray($custom = FALSE) {
  if ($custom === FALSE) {
    return parent::toArray();
  }
  else {
    $values = parent::toArray();
    foreach ($values as $key => $item) {

      // Issue #2567899 It seems it is impossible to save an empty string to an entity.
      // @see https://www.drupal.org/node/2567899
      // Solution: Set empty (aka NULL) items to an empty string.
      if (empty($item)) {
        $values[$key] = '';
      }
      else {
        $value = reset($item);
        $values[$key] = reset($value);
      }
    }
    $values['data'] = $this
      ->getData();
    return $values;
  }
}