Right now the language select is placed "near the bottom" of the fields in the form. Reordering fields sometimes puts the select between other fields. Making the language select a pseudo field, implementing hook_field_extra_fields corrects this problem. The language can now be placed just like any other field, making it possible to place it into fieldsets (e.g. vertical tabs) too.

Attached is a simple patch that ads locale_field_extra_fields() support for the language select. I'm not quite sure if the condition to check when to add the language select to the extras array is sufficient. I took the same condition as the default locale_form_alter() uses.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

plach’s picture

Component: locale.module » language system
Issue tags: +Needs committer feedback

This sounds more like a feature request to me, although in D6 CCK provided the language pseudo field. So this could be considered an oversight while porting CCK in core. Let's hear what core maintainers have to say.

However:

+++ modules/locale/locale.module	(revision )
@@ -415,6 +415,29 @@
+    if (isset($type->type) && locale_multilingual_node_type($type->type)) {

The test should check if multilingual support is different from disabled otherwise we wouldn't have the language pseudo field for tanslatable nodes.

Powered by Dreditor.

plach’s picture

Status: Needs review » Needs work
Anonymous’s picture

Status: Needs work » Needs review
plach’s picture

Status: Needs review » Needs work

@mikewink:

The current patch cannot be committed as is. Why did you ignore #1?

Anonymous’s picture

Hi plach,

I'm a bit confused. Tell me what to do and I will work on the patch? I don't know what's the problem in #1? There is a check in the patch and the patch passed the tests.

plach’s picture

The problem is that the current patch checks if multilingual support for the node type is "Enabled", but this excludes all node types having multilingual support set to "Enabled, with translation" (and ony other contrib additional mode). If the line cited in #1 is changed to check if multilingual support is not disabled the language pseudo field will appear everywhere it needs to.

plach’s picture

plach’s picture

I actually think this should go into D7, otherwise every module dealing with content language (e.g. entity_translation and i18n_node) will have to provide its implementation.

claudiu.cristea’s picture

Title: Make the language select a pseudo field to allow field reorder in node forms » Allow language select to be rearrenged inside node form
Component: language system » node system
Assigned: Unassigned » claudiu.cristea
Category: bug » feature

Because of future #375397: Make Node module optional we need to fix this in the Node module rather than Locale module.

claudiu.cristea’s picture

Status: Needs work » Needs review
FileSize
1.75 KB

Here's a patch against Node module.

claudiu.cristea’s picture

Title: Allow language select to be rearrenged inside node form » Allow language select to be rearranged inside node form

Typo fix in title.

plach’s picture

Status: Needs review » Needs work

Because of future #375397: Make Node module optional we need to fix this in the Node module rather than Locale module.

Agreed. We also should consider #540294: Move node language settings from Locale to Node module. Cannot test this now, however:

+++ b/core/modules/node/node.module
@@ -590,17 +590,24 @@ function node_add_body_field($type, $label = 'Body') {
+    // Add also the language select if Locale module is enabled
+    // and the bundle has multiligual support.

The comment should wrap at column 80.

+++ b/core/modules/node/node.module
@@ -590,17 +590,24 @@ function node_add_body_field($type, $label = 'Body') {
+        'description' => t('Locale module element'),

Shouldn't this be a "Node module element" too now?

24 days to next Drupal core point release.

claudiu.cristea’s picture

Status: Needs work » Postponed

OK. Fixed your inputs from #12 , but postponing till #540294: Move node language settings from Locale to Node module. After #540294: Move node language settings from Locale to Node module is fixed, I will reroll the patch.

claudiu.cristea’s picture

Forgot the patch :)

Gábor Hojtsy’s picture

Issue tags: +D8MI

Looks like a great suggestion for improvement.

Gábor Hojtsy’s picture

Issue tags: +language-content

Tagging for the content handling leg of D8MI.

Gábor Hojtsy’s picture

Status: Postponed » Needs review
Issue tags: -Needs committer feedback +sprint
claudiu.cristea’s picture

Status: Needs review » Needs work

The name of the node-type language variable has changed.

claudiu.cristea’s picture

Status: Needs work » Needs review
FileSize
1.77 KB

Here's a patch to review.

Gábor Hojtsy’s picture

Status: Needs review » Needs work
+++ b/core/modules/node/node.moduleundefined
@@ -603,17 +603,25 @@ function node_add_body_field($type, $label = 'Body') {
+  $locale_enabled = module_exists('locale');
...
+    // Add also the "language" select if Locale module is enabled and the bundle
+    // has multilingual support.
+    if ($locale_enabled && variable_get('node_type_language_' . $bundle->type, 0)) {

Node language is not dependent on locale in Drupal 8 anymore, it merely needs language.module.

Also, what is this giving us exactly? Placement in the form and display? Can add language to display? Will it be added automatically to the render output after this patch?

claudiu.cristea’s picture

Status: Needs work » Needs review
FileSize
57.75 KB
1.79 KB

The title says all about this feature: Allow language select to be rearranged inside node form. It's only about the form. Many site builders need flexibility on placing the Language select. That's all.

See the screenshot.

Gábor Hojtsy’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me both on patch review and visually.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

We just got under thresholds tonight, so features are back on the table.

This patch seems reasonable to me. This is technically a data structure change in D7, but one could argue it's also a bug that it doesn't do this already.

Committed and pushed to 8.x and 7.x. Thanks!

claudiu.cristea’s picture

Component: node system » language system
Status: Fixed » Patch (to be ported)

@webchick,

This patch cannot be applied to 7.x as it is... because:

I need to backport the patch first. Please revert the patch in 7.x because it will not work.

claudiu.cristea’s picture

Version: 8.x-dev » 7.x-dev

Moving to 7.x too

webchick’s picture

Version: 7.x-dev » 8.x-dev

Whoopsie. :D

Reverted 7.x commit. Thanks for catching that!

webchick’s picture

Version: 8.x-dev » 7.x-dev
Gábor Hojtsy’s picture

@claudiu.cristea: the OP (first patch) looks like it would be a good start on a D7 backport?

claudiu.cristea’s picture

@Gábor Hojtsy,

Yes, I will fix that in Locale module for D7 in order to keep the logic before #540294: Move node language settings from Locale to Node module. That patch is a good stating point. I will come with a patch later today.

Thanks.

Gábor Hojtsy’s picture

Issue tags: -sprint

Not on the D8MI sprint anymore.

tim.plunkett’s picture

Status: Patch (to be ported) » Needs review
FileSize
845 bytes

Rerolled.

tim.plunkett’s picture

Issue tags: +Needs backport to D7

Fixing tag.

hellolindsay’s picture

Any update on this? Seems there has been no new comments since May. I would very much like to be able to rearrange the language field in Drupal 7.

BrockBoland’s picture

Needs issue summary

Gábor Hojtsy’s picture

Version: 7.x-dev » 8.x-dev
Status: Needs review » Needs work
Issue tags: +sprint

I think this regressed somehow, I don't see this field on Drupal 8 anymore. :/ I think we might have forgotten to update the functionality somehow when we moved it from locale module(?).

boran’s picture

FileSize
845 bytes

The variable node_type_language_ TYPE was used to determine visibility of the language field on the field ordering list,
However the variable node_type_language_hidden_TYPE is used to determine visibility of the language field on the node/add form (see NodeFormController.php).
The same logic should be apple to both.
So change
if ($module_language_enabled && variable_get('node_type_language_' . $bundle->type, 0)) {
to
if ($module_language_enabled && !variable_get('node_type_language_hidden_' . $bundle->type, TRUE)) {

(joint analysis/fix by roderik & boran :-)

boran’s picture

FileSize
846 bytes

Oops, but in that last patch, new one attached, a "!" was missing.
(joint fix by roderik & boran)

pp’s picture

Status: Needs work » Needs review

set it needs review

webflo’s picture

Status: Needs review » Reviewed & tested by the community

The patch looks good. Reviewed and tested it.

Désiré’s picture

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

still needs tests, thanks for the review

Schnitzel’s picture

Assigned: claudiu.cristea » Schnitzel
webflo’s picture

Assigned: Schnitzel » claudiu.cristea
Status: Needs work » Needs review
FileSize
1.71 KB
2.54 KB

I wrote a small test for this. The second path should fail.

Schnitzel’s picture

as discussed with @webflo there is already a test for this: testNodeTypeInitialLanguageDefaults, but there is no test for the field rearranging, so added a new test for this.

Gábor Hojtsy’s picture

Patch looks good, adds tests to avoid this regressing again! Should be RTBC if/when it comes back green.

webflo’s picture

Status: Needs review » Reviewed & tested by the community

Yes, looks good!

webchick’s picture

Version: 8.x-dev » 7.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Committed and pushed to 8.x. Thanks!

Moving to D7.

klonos’s picture

Thanx! I really can't wait for this to get in D7 too.

boran’s picture

Just a little note: in 8.x, the language field is not visible on the manage display tab for fields. (Above we are talking about the ordering in the edit tab)

On 7.x it is there, but has the default of visible (incovenient, needs to be hidden for any sites I do).
Now I dont see the need for it in the display tab, but perhaps there is a use case that I'm not aware of, where one might want to display the language on a node. If so, should a separate issue be raised?
(PS enjoyed dc munich indeed!)

Gábor Hojtsy’s picture

@boran: indeed it not appearing on the manage display screen at all seems like (a separate) regression, that would need its own tests too. It only applies to Drupal 8. However, it sounds like an improvement that nodes would not have the language field displayed automatically anymore. Can you open an issue for this? Do you want to work on it? That would be great! :)

boran’s picture

@gabor: ok, moved to #1757504: Regression: language field is not visible on manage display, I'll aim to do it some evening this week, be patient :-)

boran’s picture

@webchick/#46:
D7 does not have this issue, the language field can be repositioned in Edit and Display tabs.
This was a D8 only (regression) bug.

Gábor Hojtsy’s picture

@boran: I'm not seeing this working on Drupal 7. Also, it says above it was committed briefly and then removed (http://drupal.org/node/1074672#comment-5667904). Are you seeing the field on the manage fields tab on Drupal 7?

klonos’s picture

...Are you seeing the field on the manage fields tab on Drupal 7?

It most certainly ain't there.

Gábor Hojtsy’s picture

Right, so this still stands as a backport. In the meantime, we lost the display field counterpart which is handled at #1757504: Regression: language field is not visible on manage display. We added tests for the manage field page here, so we should not loose it again. Same thing should go for the display fields one.

boran’s picture

51/52/53: Hmm, so this is not in D7 core..
Ah! but, it _is_ made available by the i18n module (I had tested on a few sites with that enabled).

see i18n/i18n.module i18n_language_field_extra()

function i18n_language_field_extra() {
  return array(
    'form' => array(
      'language' => array(
        'label' => t('Language'),
        'description' => t('Language selection'),
        'weight' => 0,
      ),
    ),
    'display' => array(
      'language' => array(
        'label' => t('Language'),
        'description' => t('Language'),
        'weight' => 0,
      ),
    ),
  );
}

So if this issue is back ported to core, it will need to be removed from i18n - is there much point in that? i18n will be used I imagine on D7 multilang sites.
Or am I missing something?

I also have a question on how to make the default "hidden" when one adds a field via _language_field_extra(): have not figured that out yet.

liquidcms’s picture

Status: Patch (to be ported) » Needs work

can someone do a summary of where this issue is at:

- i have core 7.15: not included there
- i have latest i18n -dev: not included there
- i looked at patch from #42 but it isn't even close to applying to the current node.module

i'll see if i can redo patch from #42 to fit with current node.module

boran’s picture

You find i18n_language_field_extra() on http://drupalcode.org/project/i18n.git/blob/refs/heads/7.x-1.x:/i18n.module and also in stable release like 7.4

liquidcms’s picture

perhaps i am missing the point of this? i have a node edit form, it has a language selector on it: http://screencast.com/t/bJiSbGmtiHm

i would like to be able to go to Manage Fields for this node type and move where that selector shows up.

i have the latest -dev of i18n. it has the code listed in #55.

the language "field" DOES NOT show in Manage Fields.

klonos’s picture

I couldn't see it either with latest devs of both core and i18n and I thought I was missing something. Turns out I was... you need to have i18n_node enabled.

liquidcms’s picture

i18n_node was enabled; doesn't help.

liquidcms’s picture

ahh.. got it.. the patch in #37 worked.

Gábor Hojtsy’s picture

I don't think we should expect multilingual Drupal 7 sites to have i18n_node module enabled, they might or might not need that functionality. The language field is already provided by locale module though in Drupal 7.

boran’s picture

I would have though that making such updates to D7 core, even for features not optimally covered by a contrib module, adds a significant risk to the (monthly) D7 upgrade process.

Gábor Hojtsy’s picture

Issue tags: -sprint

Removing from D8MI sprint, where we focus on D8 :)

  • webchick committed d96b345 on 8.3.x
    Issue #1074672 by claudiu.cristea, mikewink: Added Allow language select...
  • webchick committed 4c2bd96 on 8.3.x
    Issue #1074672 by claudiu.cristea, boran, tim.plunkett, webflo,...

  • webchick committed d96b345 on 8.3.x
    Issue #1074672 by claudiu.cristea, mikewink: Added Allow language select...
  • webchick committed 4c2bd96 on 8.3.x
    Issue #1074672 by claudiu.cristea, boran, tim.plunkett, webflo,...

  • webchick committed d96b345 on 8.4.x
    Issue #1074672 by claudiu.cristea, mikewink: Added Allow language select...
  • webchick committed 4c2bd96 on 8.4.x
    Issue #1074672 by claudiu.cristea, boran, tim.plunkett, webflo,...

  • webchick committed d96b345 on 8.4.x
    Issue #1074672 by claudiu.cristea, mikewink: Added Allow language select...
  • webchick committed 4c2bd96 on 8.4.x
    Issue #1074672 by claudiu.cristea, boran, tim.plunkett, webflo,...

  • webchick committed d96b345 on 9.1.x
    Issue #1074672 by claudiu.cristea, mikewink: Added Allow language select...
  • webchick committed 4c2bd96 on 9.1.x
    Issue #1074672 by claudiu.cristea, boran, tim.plunkett, webflo,...