Updated: Comment #43

D.o procid experiment

This issue would be a good case study to evaluate procid #2154143: Evaluating Procid, a tool to help the drupal community improve the consensus building process for d.o issues
You do not have to use procid to work on this issue, but if you want to, your feedback would be very helpful.

Problem/Motivation

Follow up issue from #1877338: Convert language admin form to new #type 'table'

If "Interface Translation" is enabled it provides a column in the language admin form which shows the 'translation ratio' of a language.

This column is being added through locale_form_language_admin_overview_form_alter and the language entities are therefore needed within the form_alter_hook.

This issue is about how to make languages entities available in locale_form_language_admin_overview_form_alter in a clean way (and it should therefore be renamed).

Currently the language entities are passed to locale_form_language_admin_overview_form_alter from LanguageListBuilder through $form['languages']['#languages'];

Sun states in #1877338: Convert language admin form to new #type 'table':

it's a bit strange that they [the language entities] are added to the top-level table element [the form], instead of the corresponding table row.

Moreover:

we actually try to avoid adding raw data objects in the $form structure; contextual data objects are added and tracked in $form_state normally; i.e., $form['languages']['#languages'] becomes $form_state['languages'] and $form['languages']['#language_default'] becomes $form_state['language_default']

Proposed resolution

  1. Pass a single language entity through the according row: So far this wasn't discussed
  2. Pass the language entities through $form_state['languages']: Same as above, not discussed yet
  3. (Re)load the language entities through LanguageManager: Patch #28, needs reroll
  4. (Re)load the language entities through LanguageListBuilder by $form_state['build_info']['callback_object']->load(): Patch #33,
  5. Implementing getEntities() in DraggableListBuilder to load the cached entities by calling $form_state['build_info']['callback_object']->getEntities(): Patch #43,

Remaining tasks

  • 1) and 2) have not been discussed.
  • 3) and 4) reload the entities, these could differ from the original language entities loaded in LanguageListBuilder. How likely is that? Performance relevant?
  • 3) would need a reroll, 4) might need an interdiff?
  • 5) needs review

Decision / discussion on what to do.

User interface changes

None. The marked column in the screenshot is being added through locale_form_language_admin_overview_form_alter, which isn't the topic of this issue.

API changes

1) - 4) don't involve API changes, 5) will at least implement getEntities() in DraggableListBuilder, wider API changes might be needed to make this consistent.

Related Issues

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sun’s picture

Status: Active » Needs review
FileSize
737 bytes

Essentially, the idea is to make this patch work.

Please do not re-test this patch. It is expected to fail.

Status: Needs review » Needs work

The last submitted patch, drupal8.language-admin-table.1.patch, failed testing.

tstoeckler’s picture

Issue tags: +Novice

Sounds like a cool Novice task so adding the tag and some specific instructions.

The code to update (on top of the patch above) is in language_admin_overview_submit():

  • Get $languages from $form_state instead of calling language_list()
  • $old_default can be removed entirely

and in locale_form_language_admin_overview_form_alter():

  • Get $languages from $form_state instead of $form

There might be something more so adding/editing/moving languages (also with locale.module turned on) should be tried to verify everything works and no notices pop-up.

It seems that 'language_default' is actually not used at all in core. (That would have to be verified by a patch.) So maybe it would be fine to remove it alltogether?

plopesc’s picture

Sorry, I created another follow up issue for #1877338: Convert language admin form to new #type 'table' which follows other approach.

#1882448: Decouple language and locale modules in language_admin_overview_form() tries to decouple the form definition and the form_alter function. Then it is not necessary add extra parameters to the $form or $form_state variables, which are not used if locale module is disabled.

Please, decide which is better and cancel the other one.

Regards

Gábor Hojtsy’s picture

Issue tags: +D8MI, +language-base

Yeah, no wonder the patch fails locale module uses the language list value at least.

YesCT’s picture

Issue tags: +Needs screenshots

tagging

pameeela’s picture

FileSize
75.8 KB

Screenshot of /admin/config/regional/language

Steps:

  1. Enable 'Language' module
  2. Go to /admin/config/regional/language

Languages | drupalcore.png

boztek’s picture

Here's a patch to implement solution in #3.

pameeela’s picture

FileSize
59.62 KB

Adding/editing/deleting/moving works well after patch.

But the default screen now shows a row each for 'Not specified' (/admin/config/regional/language/edit/und) and 'Not applicable' (/admin/config/regional/language/edit/zxx) as languages, and if you try to edit or delete you get Access Denied.

Screenshot-

Languages.png

YesCT’s picture

tagging.

I think the current state of this issue is waiting on a patch that keeps the system languages hidden.

Gábor Hojtsy’s picture

Issue tags: -Needs screenshots

System languages are definitely not there anymore. As per http://api.drupal.org/api/drupal/core%21modules%21language%21language.ad... this patch would be still needed.

victor-shelepen’s picture

Status: Needs work » Needs review
FileSize
1.33 KB

We need use language_list without parameters because

function language_list($flags = LANGUAGE_CONFIGURABLE) { ... }

It is enough.

victor-shelepen’s picture

We can also convert this form to the OOP style.

jair’s picture

Issue tags: +Needs reroll

Needs reroll

Nitesh Sethia’s picture

Assigned: Unassigned » Nitesh Sethia
FileSize
3.04 KB

Rerolling the patch #12

The last submitted patch, drupal-language-admin-form-1882712-15.patch, failed testing.

Anonymous’s picture

Issue summary: View changes

Updated issue summary.

pflame’s picture

Issue summary: View changes
Status: Needs work » Needs review
FileSize
10.65 KB

Rerolled this patch and fixed the syntax error in the patch.

Status: Needs review » Needs work

The last submitted patch, 17: drupal-language-admin-form-1882712-17.patch, failed testing.

pflame’s picture

Status: Needs work » Needs review
FileSize
10.65 KB

Sorry wrong patch file uploaded by mistake. Uploading the patch with fixed syntax error.

Status: Needs review » Needs work

The last submitted patch, 19: drupal-language-admin-form-1882712-19.patch, failed testing.

The last submitted patch, 19: drupal-language-admin-form-1882712-19.patch, failed testing.

sun’s picture

Status: Needs work » Needs review
FileSize
683 bytes

I've the impression that this entire issue + patch is obsolete, since the language overview form is not an entity listing form, because languages are configuration entities now?

That said, LanguageListController::buildForm() still appears to contain a bit of the offending code:

  public function buildForm(array $form, array &$form_state) {
    $form = parent::buildForm($form, $form_state);
    $form[$this->entitiesKey]['#languages'] = $this->entities; # <--- THIS
    $form['actions']['submit']['#value'] = t('Save configuration');
    return $form;
  }

However, grepping the Language module code, I'm not able to locate any uses that would be related to that form element property.

So perhaps, let's simply see what happens if we remove it...

Status: Needs review » Needs work

The last submitted patch, 22: drupal8.language-admin-table.22.patch, failed testing.

Gábor Hojtsy’s picture

This is where its used:

function locale_form_language_admin_overview_form_alter(&$form, &$form_state) {
  $languages = $form['languages']['#languages'];

This code may also take the languages from the language manager, if we assume that should be the same list (which should be :D).

Schnitzel’s picture

cleaning up assignees, so that Novices will try to get them =)

Schnitzel’s picture

Assigned: Nitesh Sethia » Unassigned
dermario’s picture

Assigned: Unassigned » dermario

I will try to help with this issue.

dermario’s picture

Status: Needs work » Needs review
FileSize
1.33 KB

I changed the way, how $languages are retrieved in locale_form_language_admin_overview_form_alter(), but i am not sure if i am doing it the right way.

kim.pepper’s picture

Hi Dermario,

Thanks for submitting a patch!

Can you please also provide an interdiff? This is a file that only shows the differences between your patch and the last patch.

Documentation on creating an interdiff is here: https://drupal.org/documentation/git/interdiff

Kim

dermario’s picture

FileSize
681 bytes

Hello kim.pepper,

thank you for your advice. I added my interdiff.txt file now.

Mario

sun’s picture

Thanks, @dermario! :)

While the code could manually call into LanguageManager to re-retrieve a list of languages, doing so would introduce a possibility for operating on different lists of languages, and thus, potential bugs later on.

So this is interesting... unless I missed something big, there is no way to retrieve the already loaded entities from the DraggableListController?

$form_state['build_info']['callback_object'] exists and should hold the LanguageListController.

→ Apparently, there's no getter method to retrieve the controller, just a raw array key in $form_state?

DraggableListController::$entities exists, but is protected.

→ Neither DraggableListController nor EntityListController provides a getEntities() method?

The latter is needed here, so this code is able to do:

$languages = $form_state['build_info']['callback_object']->getEntities();

Anyone any ideas?

naveko’s picture

The patch in comment #28 doesn't apply, because the file core/modules/language/lib/Drupal/language/LanguageListController.php doesn't exist.

The languages can be retrieved with the 'load' method in the $form_state['build_info']['callback_object'], which is a LanguageListBuilder object. This functions as a 'getEntities' method.

naveko’s picture

ti2m’s picture

As far as I can tell the previous patch doesn't address the open issue directly, which itself doesn't seem to have anything todo with the original issue title anymore.

In #22 sun states that the issue is resolved, but that we need to get rid of $form[$this->entitiesKey]['#languages'] = $this->entities; in

<?php
  public function buildForm(array $form, array &$form_state) {
    $form = parent::buildForm($form, $form_state);
    $form[$this->entitiesKey]['#languages'] = $this->entities; # <--- THIS
    $form['actions']['submit']['#value'] = t('Save configuration');
    return $form;
  }
?>

(a reference would be useful to why exactly we need to get rid it)

As Gabor mentions in #24, the entities are needed within locale_form_language_admin_overview_form_alter. So the real issue now is how to get the languages in locale_form_language_admin_overview_form_alter.

Gabor suggests

This code may also take the languages from the language manager, if we assume that should be the same list (which should be :D).

So that was done in #28

In contradiction to this sun then suggests

While the code could manually call into LanguageManager to re-retrieve a list of languages, doing so would introduce a possibility for operating on different lists of languages, and thus, potential bugs later on.

If we follow this then we need to be able to fetch the already loaded language entities. But the patch in [#8417017-33] uses load in LanguageListBuilder which will also re-load the entities. I'm not sure if this is in the end any different from the patch in #28 which uses the language manager.

So we either A) reload the language entities or B) we need to introduce getEntities (as sun suggests in #31) in DraggableListBuilder (as the $entities member variable is being defined there), which will then return the cached entities.

I'll start implementing getEntities to check if this would work.

Patch #28 would need a reroll due to the renaming of ListController to ListBuilder. Based on this I will also update the issue summary.

ti2m’s picture

Issue summary: View changes
FileSize
91.86 KB

major summary update

ti2m’s picture

Issue summary: View changes

minor changes

ti2m’s picture

Issue summary: View changes
YesCT’s picture

Issue summary: View changes

typo in numbers in summary. ignore this.

Sutharsan’s picture

Issue tags: -Novice

@ti2m, are you still working of this patch?
Removing 'novice' tag. I believe it is no longer applicable.

ti2m’s picture

Yes, patch is ready, just need to create it.

ti2m’s picture

Here the patch to implement getEntities() in DraggableListBuilder to retrieve the cached entities. It's a minimalistic patch, submitForm could use getEntities() as well instead of directly accessing the entities.

Status: Needs review » Needs work

The last submitted patch, 41: drupal8.language-admin-table.41.patch, failed testing.

ti2m’s picture

Status: Needs work » Needs review
FileSize
3.26 KB
2.62 KB

Patch #41 failed because SearchPageListBuilder (extending DraggableListBuilder) defined its own $entities property and initialized it with an empty array, instead of NULL which indicates that the entites were never loaded. As SearchPageListBuilder is doing that for no obvious reason I removed it.

ti2m’s picture

Issue summary: View changes
YesCT’s picture

tstoeckler’s picture

+++ b/core/lib/Drupal/Core/Config/Entity/DraggableListBuilder.php
@@ -116,8 +126,8 @@ public function buildForm(array $form, array &$form_state) {
+    $entities = $this->getEntities();
+    foreach ($entities as $entity) {

Minor, but could be collapsed into one line (i.e. (foreach ($this->getEntities() ...)))

I also think it would make sense to switch to getEntities() everywhere else directly in this issue, i.e. in submitForm() as you mentioned above.

Most importantly, though:
@ti2m as you spent a significant amount of time reading this issue, and now in contrast to me and I think many other people, know what this issue is about could you update the issue summary and title with what is now being done here? That would be incredibly helpful.

YesCT’s picture

wmortada’s picture

I have re-rolled the patch to work with commit f678e37.

There were conflicts in the following files that I resolved manually:

core\lib\Drupal\Core\Config\Entity\DraggableListBuilder.php - lines 130-139

core\modules\language\src\LanguageListBuilder.php - moved from core/modules/language/lib/Drupal/language/LanguageListBuilder.php

I have tested the page admin/config/regional/language and this appears to work. It looks the same before and after the patch.

Status: Needs review » Needs work

The last submitted patch, 48: drupal8.language-admin-table-1882712-48.patch, failed testing.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.