comparison core/lib/Drupal/Core/Field/FieldConfigBase.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents 1fec387a4317
children af1871eacc83
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
9 9
10 /** 10 /**
11 * Base class for configurable field definitions. 11 * Base class for configurable field definitions.
12 */ 12 */
13 abstract class FieldConfigBase extends ConfigEntityBase implements FieldConfigInterface { 13 abstract class FieldConfigBase extends ConfigEntityBase implements FieldConfigInterface {
14
15 use FieldInputValueNormalizerTrait;
14 16
15 /** 17 /**
16 * The field ID. 18 * The field ID.
17 * 19 *
18 * The ID consists of 3 parts: the entity type, bundle and the field name. 20 * The ID consists of 3 parts: the entity type, bundle and the field name.
261 $changed = TRUE; 263 $changed = TRUE;
262 } 264 }
263 return $changed; 265 return $changed;
264 } 266 }
265 267
266
267 /** 268 /**
268 * {@inheritdoc} 269 * {@inheritdoc}
269 */ 270 */
270 public function postCreate(EntityStorageInterface $storage) { 271 public function postCreate(EntityStorageInterface $storage) {
271 parent::postCreate($storage); 272 parent::postCreate($storage);
392 */ 393 */
393 public function getDefaultValue(FieldableEntityInterface $entity) { 394 public function getDefaultValue(FieldableEntityInterface $entity) {
394 // Allow custom default values function. 395 // Allow custom default values function.
395 if ($callback = $this->getDefaultValueCallback()) { 396 if ($callback = $this->getDefaultValueCallback()) {
396 $value = call_user_func($callback, $entity, $this); 397 $value = call_user_func($callback, $entity, $this);
398 $value = $this->normalizeValue($value, $this->getFieldStorageDefinition()->getMainPropertyName());
397 } 399 }
398 else { 400 else {
399 $value = $this->getDefaultValueLiteral(); 401 $value = $this->getDefaultValueLiteral();
400 } 402 }
401 // Allow the field type to process default values. 403 // Allow the field type to process default values.
412 414
413 /** 415 /**
414 * {@inheritdoc} 416 * {@inheritdoc}
415 */ 417 */
416 public function setDefaultValue($value) { 418 public function setDefaultValue($value) {
417 if (!is_array($value)) { 419 $this->default_value = $this->normalizeValue($value, $this->getFieldStorageDefinition()->getMainPropertyName());
418 if ($value === NULL) {
419 $value = [];
420 }
421 $key = $this->getFieldStorageDefinition()->getPropertyNames()[0];
422 // Convert to the multi value format to support fields with a cardinality
423 // greater than 1.
424 $value = [
425 [$key => $value],
426 ];
427 }
428 $this->default_value = $value;
429 return $this; 420 return $this;
430 } 421 }
431 422
432 /** 423 /**
433 * {@inheritdoc} 424 * {@inheritdoc}