Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Related #1963934: Add field sequence weight to gengo job
All fields have a clear sequence in Drupal. This needs to be preserved.
Comment | File | Size | Author |
---|---|---|---|
#35 | consider-field-sequences-35-interdiff.txt | 5.28 KB | Berdir |
#35 | consider-field-sequences-35.patch | 8.9 KB | Berdir |
| |||
#35 | consider-field-sequences-35-test-only.patch | 6.34 KB | Berdir |
#34 | consider-field-sequences-34-interdiff.txt | 2.99 KB | Berdir |
#34 | consider-field-sequences-34.patch | 6.18 KB | Berdir |
|
Comments
Comment #1
BerdirAs discussed, "All fields have a clear sequence in Drupal. This needs to be preserved." is unfortunately not completely true.
There is $field_instance['widget']['weight'] but there also things like field_groups and or http://drupal.org/project/rel, which allow to nest fields, recursively.
So if we just implement the widget weight then it will quite likely be more confusing than it is now :)
Comment #2
miro_dietikerStill, not having a clear sequence at all is even something that i consider a bug.
Here's my fancy real crazy idea ;-)
Pseudo-Form-Approach
We render the entity form and use element_children to traverse it.
Then, if we find a form element that we can map to a field, we know the sequence.
Problem: I don't know if we can map them reliable here...
Pseudo-Render-Approach
We Create an entity with some special values, trigger rendering (e.g. also with tweaked field theme functions...) and then check in the output where things went.
Problem: Well, even more crazy
Pseudo-View-Mode-Approach
Introduce a special view mode.
Ask the developer to enable this view mode to define the field sequence.
Add a note to the view mode that developers shall NOT use any grouping mechanism.
These weights we can use reliable.
The last one seems feasible to me. Minimum-intrusive as the view modes need to be enabled per content type. Although they're helpers only.
Comment #3
miro_dietikerAssigning to blueminds as it is a fundamental bug / limit of the core now.
Gengo defined this a critical problem of their customers. However now that i understand - we have grouped jobs on their side... I'm confused as things are one single job per data item anyway - do they support weighting accross grouping? ;-) *confused*
Comment #4
BerdirForm and rendering doesn't work. The grouping happens in #pre_render and preprocess functions, intercepting there would be really hard. And DS for example directly renders things into $left/right strings. And I think that it's easier to support field groups directly by reading out their children directly anyway.
A separate view mode would be relatively easy to implement but requires manual interaction. I would see that more as an option if the field order in the manage fields/widgets order should for some reason *not* be used.
Comment #5
miro_dietikerSo we try to order by weight... no own view mode reqired as long as no recursive fancyness applies.
Then we can decide if we try to implement the special cases in recursion...
Or if we support a view mode as a helper if weighted sort (due to grouping) goes wrong. Then, manual interaction required.
Comment #6
BerdirThere's one more complexity to consider here.
We're flattening/unflattening data items like crazy ourself. So a weight would need to be preserved, possibly similar to how to preserve labels now.
Comment #7
miro_dietikerWe can also flatten / unflatten weight by flatten the data like the OID in X.500 Schemas with the IANA registry, used for LDAP and SNMP:
1.3.6.1.4.1.24535 - Which is the global identifier for our company MD Systems. ;-)
(The structure is left-to-right hierarchical.)
Comment #8
miro_dietikerWe are about to introduce multilingual paragraphs support.
#2462263: Support paragraphs translation.
Even more it is important that the fields and their values are guaranteed to be displayed in the proper order.
Comment #9
miro_dietikerUnassigning.
Comment #10
miro_dietikerWhat is the status of this?
I think we should order the fields if possibly by the default form (display) mode.
Comment #11
miro_dietikerSeen again strangely odd sequenced fields such as title field last.
Comment #12
CTaPByK CreditAttribution: CTaPByK at MD Systems GmbH commentedOk, i start with this by reading discussion here and also reading related discussions about gengo job and paragraphs.
Comment #13
CTaPByK CreditAttribution: CTaPByK at MD Systems GmbH commentedThanks to @Berdir and his clear instructions i make this very basic patch without test for now. I worked on JobItemForm, next steps are review and translate forms.
Comment #15
miro_dietikerSome thoughts.
Not sure about this 1000+ strategy.
I would have expected to more define to start with the elements in the sequence of the form display and append the remaining ones?
Why do we need a special case for title?
Title is also a field that is managed in manage form display weight.
Comment #16
miro_dietikerI think the best is if you write a test that has a bunch of elements...
Then add the item, check the sequence.
Then change sequence.
Readd and recheck.
Now you are changing the sequence when showing the form.
Instead you should fix the sequence when addint the item + fields to the job!
Also the code is specific to the source. This lookup does not work for locale and other sources!
Any translator should receive the items in the correct sequence. Not just our form...
Comment #17
CTaPByK CreditAttribution: CTaPByK at MD Systems GmbH commentedI make this new patch by following suggestions #15 and #16, i modify getData method from ContentEntitySource to reorder job item data fields. In this case we have to reset job item data before every translation request. I'm not sure is this a good way, maybe just return weights from ContentEntitySource and then reorder in review and translation forms. I start some test for this but not finished yet. Screen shoots are the same as previous.
Comment #18
miro_dietikerUnsure. On one hand i would say this change could require that the item needs to be dropped / readded to the job. Fine.
But this could be an indicator that the field sequence wouldn't change until a manual cache clear is triggered? Please test and fix - or confirm it's just a test issue (thus reset workarounds are fine).
Comment #19
CTaPByK CreditAttribution: CTaPByK at MD Systems GmbH commentedOk, here is the new patch with test coverage and with some changes from #17.
Comment #21
CTaPByK CreditAttribution: CTaPByK at MD Systems GmbH commentedI bring back logic from patch #17 with test. I reset item data before we build review form. For new created jobs data fields will be ordered as we menage them, this reset data is for 'old' jobs to make them consider field sequence too.
Comment #23
CTaPByK CreditAttribution: CTaPByK at MD Systems GmbH commentedOk i try to fix some failing tests, also move part of logic to job item getData() method, screen shots are the same as previous.
Comment #24
BerdirThis information should be part of $data and set inside getData().
e.g. $data['body']['#weight'] => 5
Comment #25
CTaPByK CreditAttribution: CTaPByK at MD Systems GmbH commentedI move logic to ContentEntitySource getData() method, also i make better test with more fields.
Comment #27
CTaPByK CreditAttribution: CTaPByK at MD Systems GmbH commentedForget to pull, sorry for that...
Comment #28
BerdirI'm not sure if this is enough to make it reliable. Did you check in the local translator too?
Comment #29
miro_dietikerSwitching back. Please check input from Berdir.
Comment #30
CTaPByK CreditAttribution: CTaPByK at MD Systems GmbH commentedI spend some time on manually testing this patch for various cases and i didn't find problem. Yesterday i discuss with @Berdir about that and he will test this patch also to eventually find error in logic for some special cases.
Comment #31
miro_dietikerI tested this manually with a content type from tmgmt_demo and added a third field.
It was first after the body and later between title and body to do a second test run and compare changes.
The job item review form displayed the proper sequence.
The local / drupal user translator displayed the sequence reliably INVERSE.
Comment #32
miro_dietikerFound in LocalTaskItemForm
No idea why it thinks it needs to reverse the order "to get the correct order"...
Works perfectly after removing the array_reverse().
Comment #33
BerdirWorking a bit on this.
Comment #34
BerdirPer discussion between me and miro, refactored the sort to directly use the entity form display and not introduce #weight. Based on how it works now, it would be weird to have that when it's not actually used.
Also removed the bogus array_reverse(), which is actually the main problem here. Looking into adding test coverage for that now.
Comment #35
BerdirOk, this should do, added similar test coverage as for the content source to the local translator. I like the approach, but simplified it a bit to look for the actual element directly in the xpath instead of going for the children then in PHP.
Final test only patch with both tests, interdiff and complete patch attached.
Comment #38
Berdir