diff --git a/core/includes/entity.inc b/core/includes/entity.inc index 8d95ca2..66c9470 100644 --- a/core/includes/entity.inc +++ b/core/includes/entity.inc @@ -738,11 +738,6 @@ function entity_get_render_display(EntityInterface $entity, $view_mode) { /** * Returns the entity_form_display object associated to a bundle and form mode. * - * Use this function when assigning suggested widget options for a component - * in a given form mode. Note that they will only be actually used at render - * time if the form mode itself is configured to use dedicated widget settings - * for the bundle; if not, the 'default' form is used instead. - * * The function reads the entity_form_display object from the current * configuration, or returns a ready-to-use empty one if configuration entry * exists yet for this bundle and form mode. This streamlines manipulation of @@ -750,15 +745,18 @@ function entity_get_render_display(EntityInterface $entity, $view_mode) { * reflects the current state of the configuration. * * Example usage: - * - Set the 'body' field to be displayed and the 'field_image' field to be - * hidden on article nodes in the 'default' form mode. + * - Set the 'body' field to be displayed with the 'text_textarea_with_summary' + * widget and the 'field_image' field to be hidden on article nodes in the + * 'default' form mode. * @code * entity_get_form_display('node', 'article', 'default') * ->setComponent('body', array( * 'type' => 'text_textarea_with_summary', * 'weight' => 1, * )) - * ->removeComponent('field_image') + * ->setComponent('field_image', array( + * 'type' => 'hidden', + * )) * ->save(); * @endcode * @@ -798,10 +796,6 @@ function entity_get_form_display($entity_type, $bundle, $form_mode = 'default') /** * Returns the entity_form_display object used to render an entity form. * - * Depending on the configuration of the form mode for the bundle, this can be - * either the display object associated to the form mode, or the 'default' - * display. - * * This function should only be used internally when rendering an entity form. * When assigning suggested form display options for a component in a given form * mode, entity_get_form_display() should be used instead, in order to avoid @@ -823,11 +817,9 @@ function entity_get_render_form_display(EntityInterface $entity, $form_mode) { $entity_type = $entity->entityType(); $bundle = $entity->bundle(); - // @todo Form modes don't have custom settings yet, so always use the default - // form mode for now. - $render_form_mode = 'default'; - - $form_display = entity_get_form_display($entity_type, $bundle, $render_form_mode); + // @todo Form modes don't have custom settings yet, so just return the display + // for the form mode that was requested. + $form_display = entity_get_form_display($entity_type, $bundle, $form_mode); $form_display->originalMode = $form_mode; return $form_display; diff --git a/core/lib/Drupal/Core/Entity/EntityFormController.php b/core/lib/Drupal/Core/Entity/EntityFormController.php index 7c780f4..2332d06 100644 --- a/core/lib/Drupal/Core/Entity/EntityFormController.php +++ b/core/lib/Drupal/Core/Entity/EntityFormController.php @@ -74,8 +74,8 @@ protected function init(array &$form_state, EntityInterface $entity) { * @see Drupal\Core\Entity\EntityFormController::build() */ public function form(array $form, array &$form_state, EntityInterface $entity) { - // Get the entity_form_display object for this form mode (operation). - $form_display = entity_get_render_form_display($entity, $this->operation); + // Get the entity_form_display object for this form. + $form_display = entity_get_render_form_display($entity, 'default'); // Let modules alter the form display. $form_display_context = array( diff --git a/core/lib/Drupal/Core/Entity/EntityFormControllerNG.php b/core/lib/Drupal/Core/Entity/EntityFormControllerNG.php index f2e2e8d..f80bd5c 100644 --- a/core/lib/Drupal/Core/Entity/EntityFormControllerNG.php +++ b/core/lib/Drupal/Core/Entity/EntityFormControllerNG.php @@ -23,8 +23,8 @@ class EntityFormControllerNG extends EntityFormController { * Overrides EntityFormController::form(). */ public function form(array $form, array &$form_state, EntityInterface $entity) { - // Get the entity_form_display object for this form mode (operation). - $form_display = entity_get_render_form_display($entity, $this->operation); + // Get the entity_form_display object for this form. + $form_display = entity_get_render_form_display($entity, 'default'); // Let modules alter the form display. $form_display_context = array( diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/EntityReferenceAutocomplete.php b/core/modules/entity_reference/lib/Drupal/entity_reference/EntityReferenceAutocomplete.php index 2bd7c38..dc2628b 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/EntityReferenceAutocomplete.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/EntityReferenceAutocomplete.php @@ -75,7 +75,7 @@ public function getMatches($field, $instance, $entity_type, $entity_id = '', $pr if (isset($string)) { // Get an array of matching entities. - $widget = entity_get_form_display($instance['entity_type'], $instance['bundle'])->getComponent($instance['field_name']); + $widget = entity_get_form_display($instance['entity_type'], $instance['bundle'])->getComponent($instance['field_name'], 'default'); $match_operator = !empty($widget['settings']['match_operator']) ? $widget['settings']['match_operator'] : 'CONTAINS'; $entity_labels = $handler->getReferencableEntities($string, $match_operator, 10); diff --git a/core/modules/field/field.info.inc b/core/modules/field/field.info.inc index e9a9896..5505d33 100644 --- a/core/modules/field/field.info.inc +++ b/core/modules/field/field.info.inc @@ -144,7 +144,7 @@ function _field_info_collate_types_reset() { */ function field_behaviors_widget($op, $instance) { $info = array(); - if ($component = entity_get_form_display($instance['entity_type'], $instance['bundle'])->getComponent($instance['field_name'])) { + if ($component = entity_get_form_display($instance['entity_type'], $instance['bundle'])->getComponent($instance['field_name'], 'default')) { $info = field_info_widget_types($component['type']); } return isset($info[$op]) ? $info[$op] : FIELD_BEHAVIOR_DEFAULT; diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetBase.php b/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetBase.php index ab0d945..89c212a 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetBase.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetBase.php @@ -281,7 +281,6 @@ protected function formSingleElement(EntityInterface $entity, array $items, $del 'form' => $form, 'field' => $field, 'instance' => $instance, - 'entity_form_display' => entity_get_form_display($instance['entity_type'], $instance['bundle']), 'langcode' => $langcode, 'items' => $items, 'delta' => $delta, diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php b/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php index e2b9cad..4bc03be 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php @@ -437,7 +437,7 @@ function testFieldAttachForm() { // When generating form for all fields. $form = array(); $form_state = form_state_defaults(); - $form_state['form_display'] = entity_get_form_display($entity_type, $this->instance['bundle']); + $form_state['form_display'] = entity_get_form_display($entity_type, $this->instance['bundle'], 'default'); field_attach_form($entity, $form, $form_state); $this->assertEqual($form[$this->field_name][$langcode]['#title'], $this->instance['label'], "First field's form title is {$this->instance['label']}"); @@ -455,7 +455,7 @@ function testFieldAttachForm() { $options = array('field_name' => $this->field_name_2); $form = array(); $form_state = form_state_defaults(); - $form_state['form_display'] = entity_get_form_display($entity_type, $this->instance['bundle']); + $form_state['form_display'] = entity_get_form_display($entity_type, $this->instance['bundle'], 'default'); field_attach_form($entity, $form, $form_state, NULL, $options); $this->assertFalse(isset($form[$this->field_name]), 'The first field does not exist in the form'); @@ -479,7 +479,7 @@ function testFieldAttachExtractFormValues() { // Build the form for all fields. $form = array(); $form_state = form_state_defaults(); - $form_state['form_display'] = entity_get_form_display($entity_type, $this->instance['bundle']); + $form_state['form_display'] = entity_get_form_display($entity_type, $this->instance['bundle'], 'default'); field_attach_form($entity_init, $form, $form_state); // Simulate incoming values. diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldUnitTestBase.php b/core/modules/field/lib/Drupal/field/Tests/FieldUnitTestBase.php index e1940d5..7b1b9b1 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldUnitTestBase.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldUnitTestBase.php @@ -72,7 +72,7 @@ function createFieldWithInstance($suffix = '') { ); field_create_instance($this->$instance); - entity_get_form_display('test_entity', 'test_bundle') + entity_get_form_display('test_entity', 'test_bundle', 'default') ->setComponent($this->$field_name, array( 'type' => 'test_field_widget', 'settings' => array( diff --git a/core/modules/field/tests/modules/field_test/field_test.entity.inc b/core/modules/field/tests/modules/field_test/field_test.entity.inc index 8e3e1ff..ac0905c 100644 --- a/core/modules/field/tests/modules/field_test/field_test.entity.inc +++ b/core/modules/field/tests/modules/field_test/field_test.entity.inc @@ -227,7 +227,7 @@ function field_test_entity_nested_form($form, &$form_state, $entity_1, $entity_2 '#value' => $entity_1->$key, ); } - $form_state['form_display'] = entity_get_form_display($entity_1->entityType(), $entity_1->bundle()); + $form_state['form_display'] = entity_get_form_display($entity_1->entityType(), $entity_1->bundle(), 'default'); field_attach_form($entity_1, $form, $form_state); // Second entity. @@ -244,7 +244,7 @@ function field_test_entity_nested_form($form, &$form_state, $entity_1, $entity_2 '#value' => $entity_2->$key, ); } - $form_state['form_display'] = entity_get_form_display($entity_1->entityType(), $entity_1->bundle()); + $form_state['form_display'] = entity_get_form_display($entity_1->entityType(), $entity_1->bundle(), 'default'); field_attach_form($entity_2, $form['entity_2'], $form_state); $form['save'] = array( diff --git a/core/modules/field/tests/modules/field_test/field_test.module b/core/modules/field/tests/modules/field_test/field_test.module index 0cbbcb1..b715224 100644 --- a/core/modules/field/tests/modules/field_test/field_test.module +++ b/core/modules/field/tests/modules/field_test/field_test.module @@ -200,7 +200,7 @@ function field_test_field_attach_view_alter(&$output, $context) { */ function field_test_field_widget_form_alter(&$element, &$form_state, $context) { $instance = $context['instance']; - $entity_form_display = entity_get_form_display($instance['entity_type'], $instance['bundle']); + $entity_form_display = entity_get_form_display($instance['entity_type'], $instance['bundle'], 'default'); switch ($context['field']['field_name']) { case 'alter_test_text': drupal_set_message('Field size: ' . $entity_form_display->getWidget($context['field']['field_name'])->getSetting('size')); diff --git a/core/modules/field_ui/field_ui.admin.inc b/core/modules/field_ui/field_ui.admin.inc index 07a715b..715304c 100644 --- a/core/modules/field_ui/field_ui.admin.inc +++ b/core/modules/field_ui/field_ui.admin.inc @@ -644,7 +644,7 @@ function field_ui_widget_type_form($form, &$form_state, FieldInstance $instance) $entity_type = $instance['entity_type']; $field_name = $instance['field_name']; - $entity_form_display = entity_get_form_display($entity_type, $bundle); + $entity_form_display = entity_get_form_display($entity_type, $bundle, 'default'); $field = field_info_field($field_name); $bundles = entity_get_bundles(); $bundle_label = $bundles[$entity_type][$bundle]['label']; @@ -684,7 +684,7 @@ function field_ui_widget_type_form_submit($form, &$form_state) { $field_name = $form['#field_name']; $instance = $form['#instance']; - $entity_form_display = entity_get_form_display($entity_type, $bundle) + $entity_form_display = entity_get_form_display($entity_type, $bundle, 'default') ->setComponent($field_name, array( 'type' => $form_values['widget_type'], )); @@ -788,7 +788,7 @@ function field_ui_field_edit_form($form, &$form_state, $instance) { $bundle = $instance['bundle']; $entity_type = $instance['entity_type']; $field = field_info_field($instance['field_name']); - $entity_form_display = entity_get_form_display($entity_type, $bundle); + $entity_form_display = entity_get_form_display($entity_type, $bundle, 'default'); $bundles = entity_get_bundles(); drupal_set_title(t('%instance settings for %bundle', array( diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php b/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php index f2855c7..7116b92 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php @@ -53,7 +53,7 @@ function setUp() { ); field_create_instance($instance); - entity_get_form_display('node', 'article') + entity_get_form_display('node', 'article', 'default') ->setComponent('field_' . $vocabulary->id()) ->save(); } @@ -240,7 +240,7 @@ function assertFieldSettings($bundle, $field_name, $string = 'dummy test string' $this->assertTrue($instance['settings']['test_instance_setting'] == $string, 'Field instance settings were found.'); // Assert widget settings. - $widget_configuration = entity_get_form_display($entity_type, $bundle)->getComponent($field_name); + $widget_configuration = entity_get_form_display($entity_type, $bundle, 'default')->getComponent($field_name); $this->assertTrue($widget_configuration['settings']['test_widget_setting'] == $string, 'Field widget settings were found.'); } @@ -262,7 +262,7 @@ function testDefaultValue() { ); field_create_instance($instance); - entity_get_form_display('node', $this->type) + entity_get_form_display('node', $this->type, 'default') ->setComponent($field_name) ->save(); @@ -299,7 +299,7 @@ function testDefaultValue() { $this->assertEqual($instance['default_value'], NULL, 'The default value was correctly saved.'); // Change the widget to TestFieldWidgetNoDefault. - entity_get_form_display($instance['entity_type'], $instance['bundle']) + entity_get_form_display($instance['entity_type'], $instance['bundle'], 'default') ->setComponent($field_name, array( 'type' => 'test_field_widget_no_default', )) @@ -375,7 +375,7 @@ function testHiddenFields() { 'label' => t('Hidden field'), ); field_create_instance($instance); - entity_get_form_display('node', $this->type) + entity_get_form_display('node', $this->type, 'default') ->setComponent($field_name) ->save(); $this->assertTrue(field_read_instance('node', $field_name, $this->type), format_string('An instance of the field %field was created programmatically.', array('%field' => $field_name))); @@ -433,7 +433,7 @@ function testWidgetChange() { // Check that the field_tags field currently uses the 'options_select' // widget. - $entity_form_display = entity_get_form_display('node', 'article')->getComponent('field_tags'); + $entity_form_display = entity_get_form_display('node', 'article', 'default')->getComponent('field_tags'); $this->assertEqual($entity_form_display['type'], 'options_select'); // Check that the "Manage fields" page shows the correct widget type. @@ -458,7 +458,7 @@ function testWidgetChange() { // Check that the field uses the newly set widget. field_cache_clear(); - $widget_configuration = entity_get_form_display('node', 'article')->getComponent('field_tags'); + $widget_configuration = entity_get_form_display('node', 'article', 'default')->getComponent('field_tags'); $this->assertEqual($widget_configuration['type'], 'options_buttons'); // Go to the 'Widget type' form and check that the correct widget is