diff --git a/core/modules/entity/lib/Drupal/entity/EntityFormDisplayInterface.php b/core/modules/entity/lib/Drupal/entity/EntityFormDisplayInterface.php index 7f6e61a..1717b55 100644 --- a/core/modules/entity/lib/Drupal/entity/EntityFormDisplayInterface.php +++ b/core/modules/entity/lib/Drupal/entity/EntityFormDisplayInterface.php @@ -14,4 +14,17 @@ */ interface EntityFormDisplayInterface extends EntityDisplayBaseInterface { + + /** + * Returns the definition of a renderer plugin for the given field (e.g. + * widget, formatter). + * + * @param string $field_name + * The name of the field. + * + * @return array|null + * The widget or formatter plugin, or NULL if the field does not exist. + */ + public function getRendererDefinition($field_name); + } diff --git a/core/modules/entity/lib/Drupal/entity/Plugin/Core/Entity/EntityFormDisplay.php b/core/modules/entity/lib/Drupal/entity/Plugin/Core/Entity/EntityFormDisplay.php index 9a3f0a6..dfcedc0 100644 --- a/core/modules/entity/lib/Drupal/entity/Plugin/Core/Entity/EntityFormDisplay.php +++ b/core/modules/entity/lib/Drupal/entity/Plugin/Core/Entity/EntityFormDisplay.php @@ -45,6 +45,14 @@ public function __construct(array $values, $entity_type) { /** * {@inheritdoc} */ + public function getRendererDefinition($field_name) { + $options = getComponent($field_name); + return $this->pluginManager->getDefinition($options['type']); + } + + /** + * {@inheritdoc} + */ public function getRenderer($field_name) { if (isset($this->plugins[$field_name])) { return $this->plugins[$field_name]; diff --git a/core/modules/field/field.info.inc b/core/modules/field/field.info.inc index b6b2a95..9f5ed87 100644 --- a/core/modules/field/field.info.inc +++ b/core/modules/field/field.info.inc @@ -113,29 +113,6 @@ function _field_info_collate_types_reset() { } /** - * Determines the behavior of a widget with respect to an operation. - * - * @param string $op - * The name of the operation. Currently supported: 'default_value', - * 'multiple_values'. - * @param array $instance - * The field instance array. - * - * @return int - * One of these values: - * - 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. - */ -function field_behaviors_widget($op, $instance) { - $info = array(); - if ($component = entity_get_form_display($instance['entity_type'], $instance['bundle'], 'default')->getComponent($instance['field_name'])) { - $info = field_info_widget_types($component['type']); - } - return isset($info[$op]) ? $info[$op] : FIELD_BEHAVIOR_DEFAULT; -} - -/** * Returns a lightweight map of fields across bundles. * * The function only returns active, non deleted fields. diff --git a/core/modules/field/lib/Drupal/field/FieldInfo.php b/core/modules/field/lib/Drupal/field/FieldInfo.php index e7e46b9..aedd96b 100644 --- a/core/modules/field/lib/Drupal/field/FieldInfo.php +++ b/core/modules/field/lib/Drupal/field/FieldInfo.php @@ -575,7 +575,9 @@ public function prepareInstance($instance, $field_type) { $instance['settings'] += field_info_instance_settings($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 26264ac..afe7e08 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 @@ -104,7 +104,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); }