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
- Pass a single language entity through the according row: So far this wasn't discussed
- Pass the language entities through
$form_state['languages']
: Same as above, not discussed yet - (Re)load the language entities through
LanguageManager
: Patch #28, needs reroll - (Re)load the language entities through
LanguageListBuilder
by$form_state['build_info']['callback_object']->load()
: Patch #33, - Implementing
getEntities()
inDraggableListBuilder
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
- some overlap with #2246679: Make Language module's LanguageInterface (to be ConfigurableLanguageInterface) extend Core's LanguageInterface
- and maybe other sub issues of #2239497: [Meta] Fix ConfigurableLanguageManager getLanguages(), like #2246703: Support label keys properly in DraggableListController
- this is a follow-up from #1877338: Convert language admin form to new #type 'table'
- duplicate #1882448: Decouple language and locale modules in language_admin_overview_form()
Comment | File | Size | Author |
---|---|---|---|
#48 | drupal8.language-admin-table-1882712-48.patch | 3.5 KB | wmortada |
#43 | interdiff-1882712-33-43.txt | 2.62 KB | ti2m |
#43 | drupal8.language-admin-table.43.patch | 3.26 KB | ti2m |
#35 | interface_translation_column.png | 91.86 KB | ti2m |
#33 | drupal-language-admin-form-1882712-33.patch | 1.33 KB | naveko |
Comments
Comment #1
sunEssentially, the idea is to make this patch work.
Please do not re-test this patch. It is expected to fail.
Comment #3
tstoecklerSounds 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():
and in locale_form_language_admin_overview_form_alter():
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?
Comment #4
plopescSorry, 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
Comment #5
Gábor HojtsyYeah, no wonder the patch fails locale module uses the language list value at least.
Comment #6
YesCT CreditAttribution: YesCT commentedtagging
Comment #7
pameeela CreditAttribution: pameeela commentedScreenshot of /admin/config/regional/language
Steps:
Comment #8
boztek CreditAttribution: boztek commentedHere's a patch to implement solution in #3.
Comment #9
pameeela CreditAttribution: pameeela commentedAdding/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-
Comment #10
YesCT CreditAttribution: YesCT commentedtagging.
I think the current state of this issue is waiting on a patch that keeps the system languages hidden.
Comment #11
Gábor HojtsySystem 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.
Comment #12
victor-shelepen CreditAttribution: victor-shelepen commentedWe need use language_list without parameters because
It is enough.
Comment #13
victor-shelepen CreditAttribution: victor-shelepen commentedWe can also convert this form to the OOP style.
Comment #14
jair CreditAttribution: jair commentedNeeds reroll
Comment #15
Nitesh Sethia CreditAttribution: Nitesh Sethia commentedRerolling the patch #12
Comment #16.0
(not verified) CreditAttribution: commentedUpdated issue summary.
Comment #17
pflame CreditAttribution: pflame commentedRerolled this patch and fixed the syntax error in the patch.
Comment #19
pflame CreditAttribution: pflame commentedSorry wrong patch file uploaded by mistake. Uploading the patch with fixed syntax error.
Comment #22
sunI'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:
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...
Comment #24
Gábor HojtsyThis is where its used:
This code may also take the languages from the language manager, if we assume that should be the same list (which should be :D).
Comment #25
Schnitzel CreditAttribution: Schnitzel commentedcleaning up assignees, so that Novices will try to get them =)
Comment #26
Schnitzel CreditAttribution: Schnitzel commentedComment #27
dermarioI will try to help with this issue.
Comment #28
dermarioI 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.
Comment #29
kim.pepperHi 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
Comment #30
dermarioHello kim.pepper,
thank you for your advice. I added my interdiff.txt file now.
Mario
Comment #31
sunThanks, @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 theLanguageListController
.→ 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
norEntityListController
provides agetEntities()
method?The latter is needed here, so this code is able to do:
Anyone any ideas?
Comment #32
naveko CreditAttribution: naveko commentedThe 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.
Comment #33
naveko CreditAttribution: naveko commentedAdded a patch as a solution for https://drupal.org/comment/8417017#comment-8417017
Comment #34
ti2m CreditAttribution: ti2m commentedAs 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(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
So that was done in #28
In contradiction to this sun then suggests
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
inLanguageListBuilder
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) inDraggableListBuilder
(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.
Comment #35
ti2m CreditAttribution: ti2m commentedmajor summary update
Comment #36
ti2m CreditAttribution: ti2m commentedminor changes
Comment #37
ti2m CreditAttribution: ti2m commentedComment #38
YesCT CreditAttribution: YesCT commentedtypo in numbers in summary. ignore this.
Comment #39
Sutharsan CreditAttribution: Sutharsan commented@ti2m, are you still working of this patch?
Removing 'novice' tag. I believe it is no longer applicable.
Comment #40
ti2m CreditAttribution: ti2m commentedYes, patch is ready, just need to create it.
Comment #41
ti2m CreditAttribution: ti2m commentedHere the patch to implement
getEntities()
inDraggableListBuilder
to retrieve the cached entities. It's a minimalistic patch,submitForm
could usegetEntities()
as well instead of directly accessing the entities.Comment #43
ti2m CreditAttribution: ti2m commentedPatch #41 failed because
SearchPageListBuilder
(extendingDraggableListBuilder
) defined its own$entities
property and initialized it with an empty array, instead of NULL which indicates that the entites were never loaded. AsSearchPageListBuilder
is doing that for no obvious reason I removed it.Comment #44
ti2m CreditAttribution: ti2m commentedComment #45
YesCT CreditAttribution: YesCT commentedComment #46
tstoecklerMinor, 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.
Comment #47
YesCT CreditAttribution: YesCT commentedrelated
#2246679: Make Language module's LanguageInterface (to be ConfigurableLanguageInterface) extend Core's LanguageInterface
and maybe other sub issues of #2239497: [Meta] Fix ConfigurableLanguageManager getLanguages()
[edit: oops. might not be appropriate here. I might have had the wrong issue.]
Comment #48
wmortada CreditAttribution: wmortada as a volunteer commentedI 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.