W3cubDocs

/Drupal 8

public function BaseFieldDefinition::setDefaultValue

public BaseFieldDefinition::setDefaultValue($value)

File

core/lib/Drupal/Core/Field/BaseFieldDefinition.php, line 478

Class

BaseFieldDefinition
A class for defining entity fields.

Namespace

Drupal\Core\Field

Code

public function setDefaultValue($value) {
  if ($value === NULL) {
    $value = [];
  }
  // Unless the value is an empty array, we may need to transform it.
  if (!is_array($value) || !empty($value)) {
    if (!is_array($value)) {
      $value = array(array($this->getMainPropertyName() => $value));
    }
    elseif (is_array($value) && !is_numeric(array_keys($value) [0])) {
      $value = array(0 => $value);
    }
  }
  $this->definition['default_value'] = $value;
  return $this;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Field!BaseFieldDefinition.php/function/BaseFieldDefinition::setDefaultValue/8.1.x