diff -u b/core/modules/field/field.api.php b/core/modules/field/field.api.php --- b/core/modules/field/field.api.php +++ b/core/modules/field/field.api.php @@ -729,8 +729,9 @@ * arguments received by hook_field_widget_form(): * - form: The form structure to which widgets are being attached. This may be * a full form structure, or a sub-element of a larger form. - * - field: The field structure. - * - instance: The field instance structure. + * - field_definition: The field definition. + * - entity_type: The entity type. + * - bundle: The entity bundle. * - langcode: The language associated with $items. * - items: Array of default values for this field. * - delta: The order of this item in the array of subelements (0, 1, 2, etc). @@ -764,9 +765,9 @@ * arguments received by hook_field_widget_form(): * - "form": The form structure where widgets are being attached to. This * might be a full form structure, or a sub-element of a larger form. - * - "field": The field structure. - * - "instance": The field instance structure. - * - "langcode": The language associated with $items. + * - "field_definition": The field definition. + * - "entity_type": The entity type. + * - "bundle": The entity bundle. * - "items": Array of default values for this field. * - "delta": The order of this item in the array of subelements (0, 1, 2, * etc). diff -u b/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetBase.php b/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetBase.php --- b/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetBase.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetBase.php @@ -273,6 +273,8 @@ $context = array( 'form' => $form, 'field_definition' => $this->field_definition, + 'entity_type' => $entity->entityType(), + 'bundle' => $entity->bundle(), 'langcode' => $langcode, 'items' => $items, 'delta' => $delta, diff -u b/core/modules/field/tests/modules/field_test/field_test.module b/core/modules/field/tests/modules/field_test/field_test.module --- b/core/modules/field/tests/modules/field_test/field_test.module +++ b/core/modules/field/tests/modules/field_test/field_test.module @@ -226,12 +226,12 @@ $field_name = $context['field_definition']['field_name']; switch ($field_name) { case 'alter_test_text': - $instance = field_info_instance($element['value']['#entity_type'], $field_name, $element['value']['#bundle']); + $instance = field_info_instance($context['entity_type'], $field_name, $context['bundle']); drupal_set_message('Field size: ' . $instance->getWidget()->getSetting('size')); break; case 'alter_test_options': - $instance = field_info_instance($element['value']['#entity_type'], $field_name, $element['value']['#bundle']); + $instance = field_info_instance($context['entity_type'], $field_name, $context['bundle']); drupal_set_message('Widget type: ' . $instance->getWidget()->getPluginId()); break; }