diff --git a/core/modules/entity/lib/Drupal/entity/EntityDisplayBase.php b/core/modules/entity/lib/Drupal/entity/EntityDisplayBase.php index 6a1c9de..6ac53e2 100644 --- a/core/modules/entity/lib/Drupal/entity/EntityDisplayBase.php +++ b/core/modules/entity/lib/Drupal/entity/EntityDisplayBase.php @@ -268,4 +268,13 @@ public function getHighestWeight() { return $weights ? max($weights) : NULL; } + /** + * {@inheritdoc} + */ + public function getRendererDefinition($field_name) { + if ($options = $this->getComponent($field_name)) { + return $this->pluginManager->getDefinition($options['type']); + } + } + } diff --git a/core/modules/entity/lib/Drupal/entity/EntityDisplayBaseInterface.php b/core/modules/entity/lib/Drupal/entity/EntityDisplayBaseInterface.php index 06647e7..a137e32 100644 --- a/core/modules/entity/lib/Drupal/entity/EntityDisplayBaseInterface.php +++ b/core/modules/entity/lib/Drupal/entity/EntityDisplayBaseInterface.php @@ -81,6 +81,19 @@ public function removeComponent($name); */ public function getHighestWeight(); + + /** + * Returns the definition of the renderer plugin used for a component. + * + * @param string $field_name + * The name of the field. + * + * @return array|null + * The definition of the renderer plugin (e.g. widget, formatter), or + * NULL if the component is not set. + */ + public function getRendererDefinition($field_name); + /** * Returns the renderer plugin for a field (e.g. widget, formatter). * diff --git a/core/modules/field/field.info.inc b/core/modules/field/field.info.inc index 824d74e..40b7138 100644 --- a/core/modules/field/field.info.inc +++ b/core/modules/field/field.info.inc @@ -126,6 +126,10 @@ function _field_info_collate_types_reset() { * - FIELD_BEHAVIOR_NONE: Do nothing for this operation. * - FIELD_BEHAVIOR_CUSTOM: Use the widget's callback function. * - FIELD_BEHAVIOR_DEFAULT: Use field.module default behavior. + * + * @deprecated as of Drupal 8.0. Use + * - entity_get_form_display()->getRendererDefinition()[$op] + * */ function field_behaviors_widget($op, $instance) { $info = array(); diff --git a/core/modules/field/lib/Drupal/field/FieldInfo.php b/core/modules/field/lib/Drupal/field/FieldInfo.php index 2639c25..6058e57 100644 --- a/core/modules/field/lib/Drupal/field/FieldInfo.php +++ b/core/modules/field/lib/Drupal/field/FieldInfo.php @@ -586,7 +586,9 @@ public function prepareInstance($instance, $field_type) { $instance['settings'] += $this->fieldTypeManager->getDefaultInstanceSettings($field_type); // Set a default value for the instance. - if (field_behaviors_widget('default value', $instance) == FIELD_BEHAVIOR_DEFAULT && !isset($instance['default_value'])) { + $formDisplay = entity_get_form_display($instance['entity_type'], $instance['bundle'], 'default'); + $rendererDefinition = $formDisplay->getRendererDefinition($instance['field_name']); + if ($rendererDefinition['default_value'] == FIELD_BEHAVIOR_DEFAULT && !isset($instance['default_value'])) { $instance['default_value'] = NULL; } diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldInstanceEditForm.php b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldInstanceEditForm.php index 046e012..f9ea2fa 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldInstanceEditForm.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldInstanceEditForm.php @@ -166,7 +166,9 @@ public function buildForm(array $form, array &$form_state, FieldInstanceInterfac $form['instance']['settings']['#weight'] = 10; // Add handling for default value if not provided by any other module. - if (field_behaviors_widget('default_value', $this->instance) == FIELD_BEHAVIOR_DEFAULT && empty($this->instance['default_value_function'])) { + $formDisplay = entity_get_form_display($this->instance['entity_type'], $this->instance['bundle'], 'default'); + $rendererDefinition = $formDisplay->getRendererDefinition($instance['field_name']); + if ($rendererDefinition['default_value'] == FIELD_BEHAVIOR_DEFAULT && empty($this->instance['default_value_function'])) { $form['instance']['default_value_widget'] = $this->getDefaultValueWidget($field, $form, $form_state); }