diff -u b/core/modules/datetime/datetime.module b/core/modules/datetime/datetime.module --- b/core/modules/datetime/datetime.module +++ b/core/modules/datetime/datetime.module @@ -265,22 +265,29 @@ * Callback for $instance['default_value_function'], as implemented by * Drupal\datetime\Plugin\field\widget\DateTimeDatepicker. * - * @param \Drupal\Core\Entity\EntityInterface $entity - * The entity being created. - * @param \Drupal\Core\Entity\Field\FieldDefinitionInterface $field_definition - * The field definition. + * @param $entity_type + * + * @param $entity + * + * @param array $field + * + * @param array $instance + * + * @param $langcode + * * * @return array - * The default value. + * */ -function datetime_default_value(EntityInterface $entity, FieldDefinitionInterface $field_definition) { +function datetime_default_value($entity, $field, $instance, $langcode) { + $value = ''; $date = ''; - if ($field_definition->getFieldSetting('default_value') == 'now') { + if ($instance['settings']['default_value'] == 'now') { // A default value should be in the format and timezone used for date // storage. $date = new DrupalDateTime('now', DATETIME_STORAGE_TIMEZONE); - $storage_format = $field_definition->getFieldSetting('datetime_type') == 'date' ? DATETIME_DATE_STORAGE_FORMAT: DATETIME_DATETIME_STORAGE_FORMAT; + $storage_format = $field['settings']['datetime_type'] == 'date' ? DATETIME_DATE_STORAGE_FORMAT: DATETIME_DATETIME_STORAGE_FORMAT; $value = $date->format($storage_format); } diff -u b/core/modules/field/field.module b/core/modules/field/field.module --- b/core/modules/field/field.module +++ b/core/modules/field/field.module @@ -440,6 +440,28 @@ } /** + * Helper function to get the default value for a field on an entity. + * + * @param \Drupal\Core\Entity\EntityInterface $entity + * The entity for the operation. + * @param $field + * The field structure. + * @param $instance + * The instance structure. + * @param $langcode + * The field language to fill-in with the default value. + * + * @return array + * The default value for the field. + * + * @deprecated as of Drupal 8.0. Use + * $instance->getFieldDefaultValue($entity) + */ +function field_get_default_value(EntityInterface $entity, $field, $instance, $langcode = NULL) { + return $instance->getFieldDefaultValue($entity); +} + +/** * Callback for usort() within theme_field_multiple_value_form(). * * Sorts using ['_weight']['#value'] diff -u b/core/modules/field/lib/Drupal/field/Plugin/Core/Entity/FieldInstance.php b/core/modules/field/lib/Drupal/field/Plugin/Core/Entity/FieldInstance.php --- b/core/modules/field/lib/Drupal/field/Plugin/Core/Entity/FieldInstance.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Core/Entity/FieldInstance.php @@ -156,8 +156,12 @@ * The function will be called with the following arguments: * - \Drupal\Core\Entity\EntityInterface $entity * The entity being created. - * - \Drupal\Core\Entity\Field\FieldDefinitionInterface $field_definition - * The field definition. + * - \Drupal\field\Plugin\Core\Entity\Field $field + * The field object. + * - \Drupal\field\Plugin\Core\Entity\FieldInstance $instance + * The field instance object. + * - string $langcode + * The language of the entity being created. * It should return an array of default values, in the same format as the * $default_value property. * @@ -565,7 +569,7 @@ public function getFieldDefaultValue(EntityInterface $entity) { if (!empty($this->default_value_function)) { $function = $this->default_value_function; - return $function($entity, $this); + return $function($entity->entityType(), $entity, $this->getField(), $this, $entity->language()->id); } elseif (!empty($this->default_value)) { return $this->default_value; reverted: --- b/core/modules/field/tests/modules/field_test/field_test.field.inc +++ a/core/modules/field/tests/modules/field_test/field_test.field.inc @@ -194,7 +194,7 @@ /** * Sample 'default value' callback. */ +function field_test_default_value(EntityInterface $entity, $field, $instance) { -function field_test_default_value() { return array(array('value' => 99)); } reverted: --- b/core/modules/system/tests/modules/entity_test/entity_test.module +++ a/core/modules/system/tests/modules/entity_test/entity_test.module @@ -9,7 +9,6 @@ use Drupal\entity\Plugin\Core\Entity\EntityFormDisplay; use Drupal\field\Plugin\Core\Entity\Field; use Drupal\field\Plugin\Core\Entity\FieldInstance; -use Drupal\Core\Entity\Field\FieldDefinitionInterface; /** * Filter that limits test entity list to revisable ones. @@ -476,8 +475,8 @@ * @param string $langcode * The field language code to fill-in with the default value. */ +function entity_test_field_default_value(EntityInterface $entity, Field $field, FieldInstance $instance, $langcode) { + return array(array('value' => $field['field_name'] . '_' . $langcode)); -function entity_test_field_default_value(EntityInterface $entity, FieldDefinitionInterface $field_definition) { - return array(array('value' => $field_definition->getFieldName() . '_' . $entity->language()->id)); } /**