Repositioning of Language field fails. It can not be placed after the body field once it has been placed above it.

Steps to reproduce:

1. git pull
2. drush si
3. drush en translation language
4. Login as admin and using admin/config/regional/language, add a language.
5. Using admin/structure/types/manage/article under language settings select Show language selector, Enable translation and then Save Content Type.
5. Edit Article. Select Show language selector, Enable translation, Save Content Type
6. View node/add/article and notice that the Language field comes right after Image. (Screen shot)
Screen Shot 2013-02-09 at 10.57.39.png
7. Using admin/structure/types/manage/article/fields, move Language after Title. (Screen shot)
Screen Shot 2013-02-09 at 11.00.10.png
8. View node/add/article and notice that the Language field comes after Title. (Screen shot)
Screen Shot 2013-02-09 at 11.04.32.png
9. Using admin/structure/types/manage/article/fields, move Language after Body. (Screen shot)
Screen Shot 2013-02-09 at 11.05.08.png
10. View node/add/article and notice that the Language field DOES NOT come after Title. (Screen shot)
Screen Shot 2013-02-09 at 11.06.57.png

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mitron’s picture

Issue summary: View changes

Updated issue summary.

mitron’s picture

Title: Language Field get "Stuck" after Title » Language Field gets "Stuck" after Title
ChrisMiller627’s picture

Assigned: Unassigned » ChrisMiller627
ChrisMiller627’s picture

Assigned: ChrisMiller627 » Unassigned

So the issue here appears to be with the way the language field information is stored. The two naming conventions that look to be in dispute are language and langcode. I'm willing to bet by correcting the naming conventions of the machine name this issue will be solved.

In the cache_field table the language field weight is being stored successfully in the extra field bundle field_info:bundle_extra:node:article. However, when the language select field is rendered on the node form in node/add/article, it's named langcode.

I traced the issue back a ways through the field.module, and isolated the problem to what is returned from field_info_extra_fields() in _field_extra_fields_pre_render(). $extra_fields is populated incorrectly with the name 'language,' while $elements contains the name 'langcode.' This discrepancy wiIl prevent $elements['langcode'] from being updated correctly. I added a simple conditional below to demonstrate the issue:

// in field.module, line 764
function _field_extra_fields_pre_render($elements) {
  $entity_type = $elements['#entity_type'];
  $bundle = $elements['#bundle'];

  $extra_fields = field_info_extra_fields($entity_type, $bundle, 'form');
  foreach ($extra_fields as $name => $settings) {
    if (isset($elements[$name])) {
      $elements[$name]['#weight'] = $settings['weight'];
    }
    // simple conditional demonstration to set the weight correctly
    if ($name == 'language') {
      $elements['langcode']['#weight'] = $settings['weight'];
    }
  }

  return $elements;
}

With that conditional added, the weight is correctly rendered on the node edit form.

I'm not entirely familiar enough with the larger scope of why the language module naming conventions are what they are, so I'll let someone else work through this a bit more. Hope this information helps however.

swentel’s picture

Component: language system » field system
Issue tags: +D8MI, +Field API

Confirmed this is still an issue.

This is probably more a field api problem then language, so changing the component.

swentel’s picture

Status: Active » Needs review
FileSize
898 bytes

This fixes it

Status: Needs review » Needs work

The last submitted patch, 1912992-5.patch, failed testing.

swentel’s picture

Status: Needs work » Needs review
FileSize
2.54 KB
3.41 KB

fixing tests

Status: Needs review » Needs work

The last submitted patch, 1912992-7.patch, failed testing.

swentel’s picture

Status: Needs work » Needs review
FileSize
773 bytes
3.16 KB

Status: Needs review » Needs work

The last submitted patch, 1912992-9.patch, failed testing.

swentel’s picture

Status: Needs work » Needs review
FileSize
778 bytes
3.92 KB

Djeez

amateescu’s picture

Status: Needs review » Reviewed & tested by the community

This is so confusing! I had to dig a bit in EntityFormController and the fix is correct. RTBC hoping that the tests will pass this time.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll

Patch no longer applies.

amateescu’s picture

Status: Needs work » Reviewed & tested by the community
Issue tags: -Needs reroll
FileSize
3.9 KB

Rerolled.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Wow, what a fantastic bug report! :) Glad the fix was so easy.

Committed and pushed to 8.x. Thanks!

webchick’s picture

Issue summary: View changes

Updated issue summary.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.