You are here

public function FieldConfigBase::setDefaultValueCallback in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Field/FieldConfigBase.php \Drupal\Core\Field\FieldConfigBase::setDefaultValueCallback()
  2. 9 core/lib/Drupal/Core/Field/FieldConfigBase.php \Drupal\Core\Field\FieldConfigBase::setDefaultValueCallback()

Sets a custom default value callback.

If set, the callback overrides any set default value.

Parameters

string|null $callback: The callback to invoke for getting the default value (pass NULL to unset a previously set callback). The callback will be invoked with the following arguments:

It should return the default value in the format accepted by the setDefaultValue() method.

Return value

$this

Overrides FieldConfigInterface::setDefaultValueCallback

File

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

Class

FieldConfigBase
Base class for configurable field definitions.

Namespace

Drupal\Core\Field

Code

public function setDefaultValueCallback($callback) {
  $this->default_value_callback = $callback;
  return $this;
}