Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. FieldConfigBase.php

function FieldConfigBase::getDefaultValue

Overrides FieldDefinitionInterface::getDefaultValue

File

core/lib/Drupal/Core/Field/FieldConfigBase.php, line 425

Class

FieldConfigBase
Base class for configurable field definitions.

Namespace

Drupal\Core\Field

Code

public function getDefaultValue(FieldableEntityInterface $entity) {
    // Allow custom default values function.
    if ($callback = $this->getDefaultValueCallback()) {
        $value = call_user_func($callback, $entity, $this);
        $value = $this->normalizeValue($value, $this->getFieldStorageDefinition()
            ->getMainPropertyName());
    }
    else {
        $value = $this->getDefaultValueLiteral();
    }
    // Allow the field type to process default values.
    $field_item_list_class = $this->getClass();
    return $field_item_list_class::processDefaultValue($value, $entity, $this);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal