diff --git a/core/lib/Drupal/Core/Entity/EntityFormController.php b/core/lib/Drupal/Core/Entity/EntityFormController.php index 372bf35..e4acf56 100644 --- a/core/lib/Drupal/Core/Entity/EntityFormController.php +++ b/core/lib/Drupal/Core/Entity/EntityFormController.php @@ -186,12 +186,16 @@ public function processForm($element, $form_state, $form) { } } - // Hide extra fields. + // Hide or assign weights for extra fields. $extra_fields = field_info_extra_fields($this->entity->entityType(), $this->entity->bundle(), 'form'); foreach ($extra_fields as $extra_field => $info) { - if (!$this->getFormDisplay($form_state)->getComponent($extra_field)) { + $component = $this->getFormDisplay($form_state)->getComponent($extra_field); + if (!$component) { $element[$extra_field]['#access'] = FALSE; } + else { + $element[$extra_field]['#weight'] = $component['weight']; + } } return $element; diff --git a/core/modules/comment/lib/Drupal/comment/CommentFormController.php b/core/modules/comment/lib/Drupal/comment/CommentFormController.php index ad4b9a0..6503a3a 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentFormController.php +++ b/core/modules/comment/lib/Drupal/comment/CommentFormController.php @@ -46,9 +46,7 @@ public function form(array $form, array &$form_state) { $form += $form_state['comment_preview']; } - $form['author'] = array( - '#weight' => 10, - ); + $form['author'] = array(); // Display author information in a details element for comment moderators. if ($is_admin) { $form['author'] += array( diff --git a/core/modules/field/lib/Drupal/field/FieldInfo.php b/core/modules/field/lib/Drupal/field/FieldInfo.php index 2639c25..f791af8 100644 --- a/core/modules/field/lib/Drupal/field/FieldInfo.php +++ b/core/modules/field/lib/Drupal/field/FieldInfo.php @@ -538,12 +538,12 @@ public function getBundleExtraFields($entity_type, $bundle) { // Cache miss: read from hook_field_extra_fields(). Note: given the current // shape of the hook, we have no other way than collecting extra fields on // all bundles. - $info = array(); + $info = array('form' => array(), 'display' => array()); $extra = $this->moduleHandler->invokeAll('field_extra_fields'); drupal_alter('field_extra_fields', $extra); - // Merge in saved settings. + if (isset($extra[$entity_type][$bundle])) { - $info = $this->prepareExtraFields($extra[$entity_type][$bundle], $entity_type, $bundle); + $info += $extra[$entity_type][$bundle]; } // Store in the 'static' and persistent caches. @@ -593,38 +593,4 @@ public function prepareInstance($instance, $field_type) { return $instance; } - /** - * Prepares 'extra fields' for the current run-time context. - * - * @param $extra_fields - * The array of extra fields, as collected in hook_field_extra_fields(). - * @param $entity_type - * The entity type. - * @param $bundle - * The bundle name. - * - * @return - * The list of extra fields completed for the current runtime context. - */ - public function prepareExtraFields($extra_fields, $entity_type, $bundle) { - $entity_type_info = entity_get_info($entity_type); - $bundle_settings = field_bundle_settings($entity_type, $bundle); - $extra_fields += array('form' => array(), 'display' => array()); - - $result = array(); - // Extra fields in forms. - foreach ($extra_fields['form'] as $name => $field_data) { - $settings = isset($bundle_settings['extra_fields']['form'][$name]) ? $bundle_settings['extra_fields']['form'][$name] : array(); - if (isset($settings['weight'])) { - $field_data['weight'] = $settings['weight']; - } - $result['form'][$name] = $field_data; - } - - // Extra fields in displayed entities. - $result['display'] = $extra_fields['display']; - - return $result; - } - }