Spin-off from #657972: Make field fallback logic actually reusable.
The TF code is black magic even to me after a couple weeks away from that area. I had a hell of a hard time making sense of the logic in the patch above.
- A docblock at the beginning of field.multilingual.inc explaining the general logic of TF regarding f_a_*() functions, field_invoke(), hook_f_m_fallback_alter(), language handlers (which for instance I don't know the first thing about). Doesn't need to be two pages, but should give the overall logic of the architecture and mechanisms, which currently is only scattered in code here and there.
- $options['language'] is currently not documented at all in the PHPdoc for _field_invoke() - not even in HEAD. Its behavior should be made extra clear, as well as the fact that it can be an array per field. The fact that the function will iterate on all language of all fields, or on the specific field and /or language specified in $options should also be stated in a PHPdoc paragraph below the function description.
- I'd actually advocate that the $language_suggestion logic in f_m_available_languages() needs to be moved inside _field_invoke. If there is an explicit language, use it, or else iterate on all available_languages(). Then f_m_available_languages() == the current _f_m_available_languages() helper func.
Would make the TF logic of field_invoke() clearer by looking at the code. Right now all you can see "is iterate on all available_languages()" and you need to read the code in f_m_available_languages() to understand that it restricts to $options['language'], which is not conveyed by the func name.
- The function names in field.multilingual.inc are cryptic. I'm really not a fan of the field_multilingual_* namespace, really convoluted. The fact that functions are grouped in a 'multilingual.inc' file is one thing, this doesn't mean we need to use that as a namespace.
For instance, field_multilingual_available_languages() could be field_available_languages(). Some functions could keep the 'multilingual' term, but only because it's needed / relevant for what the function does (e.g field_multilingual_enabled())
- field_multilingual_content_languages() doesn't seem like it belongs to field API. It's more generic than that.
Comment | File | Size | Author |
---|---|---|---|
#41 | tf-664136-41.patch | 703 bytes | plach |
#35 | tf-664136-35.patch | 4.88 KB | plach |
#18 | tf-664136-18.patch | 4.87 KB | plach |
#15 | tf-664136-15.patch | 4.9 KB | plach |
#13 | drupal.tf-docs.13.patch | 5.01 KB | sun |
Comments
Comment #1
sun+1
Comment #2
plachI apologize for the code above being poorly documented but it was just a tentative approach. It didn't mean to be a definitive patch, so I didn't spend much time on that aspect. If the overall idea is deemed good, I'll document it the best I can.
Comment #3
plachComment #4
yched CreditAttribution: yched commented@plach: I tried to keep issues and remarks that are actually tied to the 'fallback logic' within my comments in #664136: Enhance TF code documentation, so that the patch can be polished and get in faster. The remarks above are more general about TF code as currently stands.
Comment #5
plachOk, I almost finished to implement your suggestions. I tried to fix all the docs except the field.multilingual.inc initial docblock in the other patch. I'll post it tomorrow morning.
Comment #6
yched CreditAttribution: yched commentedCool, thks plach !
Comment #9
catchDemoting from critical, if we held up core releases on code only one person actually understands we'd never release anything.
Comment #10
plachAnd here is the documentation: I tried to cover all the TF aspects. When this gets committed I'll link http://api.drupal.org/api/drupal/modules--field--field.multilingual.inc/7 from the D6/D7 upgrade guide.
Comment #11
plachRetitling as the readability has been addressed in #657972: Make field fallback logic actually reusable.
Comment #12
yched CreditAttribution: yched commentedAwesome. A couple remarks :
Minor: the "as a matter of fact" bit sounds a bit casual IMO.
+ using the word "share" is a bit ambiguous (kind of clashes with "shared fields"...)
It looks like this bit belongs to the previous paragraph (that mentions hook_field_available_languages_alter()) ?
"where $field is the array returned by field_info_field()" is a bit extra verbose IMO + messes the flow of the sentence.
"which narrows the processing to a single language" ?
+ typo "langugage"
Actually, I'm not sure that last sentence is needed. Possibly too much detail on an internal function ? Your call.
"of" needs to be removed in "most of field_attach_X() functions".
+ I'd add "As a result, most field_attach_X() functions ..." at the beginning of the sentence, to make it clear that this is a consequence of _field_invoke() behavior.
Trailing whitespace
Other than that,
- the "2)" paragraph and the last paragraph look like they're dealing with the same topic, so the layout between the two of them is a bit unclear / redundant to me.
- I still don't actually get what is a 'translation handler' ;-) Is there a short way to roughly explain this here ?
128 critical left. Go review some!
Comment #13
sunSlightly revamped, reworded, restyled this. Seems to address most of yched's concerns already.
Comment #14
yched CreditAttribution: yched commentedActually, a couple still apply ;-)
This part got more confuse, I think.
+ 'cardinality' is dangerous here, clashes with the usual sense of 'field cardinality'
Looks like this belongs one paragraph up, where hook_field_available_languages_alter() is mentioned.
The 2 paragraphs basically say the same thing ?
The $field['translatable'] property would be clearer ?
"Most of f_a_X() functions" -> "Most f_a_X() functions"
badly formed sentence
The end of the doc is much clearer IMO.
128 critical left. Go review some!
Comment #15
plachThis should take care of #14.
Comment #16
yched CreditAttribution: yched commentedI hate to be such a sucker :-(, but I'd really prefer we didn't mention the 'cardinality' of the set of languages.
Can we agree on "For untranslatable fields this set only contains LANGUAGE_NONE." ?
Other than that, RTBC. Great writeup.
Comment #17
sunAfter working on the previous patch I thought quite extensively about this issue, and I think this @defgroup will be the #1 lookup/search target for anyone who tries to understand fields + languages + multilingual fields support + translatable fields + field value handling in multilingual environments + interaction with other workflows (like permissions, AJAX, anyone?) + whatnot.
I think we need to re-think. I think we need to take a large step back. And look at what we have done, possibly for the first time. :)
We need to answer questions. To kick-start - perhaps but not necessarily in this order:
<schizophrenic>
</schizophrenic>
Possibly more. Though, answering those questions step by step in this order will likely lead to a @defgroup description that humans are able to understand. :)
Comment #18
plachThis one takes care of #16.
I ain't sure that the answers to the above questions fit in this initial doc block. Maybe a dedicated page in the Field API handbook?
Comment #19
sunTo some extent, these docs belong into code. To my knowledge, the best @defgroup example we currently have is http://api.drupal.org/api/group/ajax/7
One important observation on above list of questions is that the latter ones (starting somewhere around 10.) are more or less covered in this patch. But the preceding and some others are not.
Comment #20
plachYes, I noticed that. I didn't know such a complete documentation with code excerpts and things could fit into source code.
I'd like to read yched's opinion before starting everything again.
Anyway I'm a little bit worried about #2: I just realized that in this context we don't have a solid difference between the two terms, in my mind they have a slightly different meaning, but that's absolutely not reflected by code.
Comment #21
plachyched?
Comment #23
yched CreditAttribution: yched commentedYup, sorry for the delay, only got like one hour a day in front of the keyboard for the time being :-).
I think the questions in sun's #17 are valid, of course. However, the scope of this issue was primarily to get the general *internal* workflow (like : how does it work ? how wrt to the general Field API workflow ? - which was unclear even to me a couple weeks after the initial TF patch landed) written down somewhere instead of encrypted in obscure code in _field_invoke(). The patch in #18 adresses that, and as such is worth committing IMO.
Comment #24
plach@sun: So? RTBC or needs work?
Comment #26
plachStill waiting to know if it's ok to commit this and answer the questions from #17 in a handbook page.
Comment #27
sunLet's get some core maintainer feedback on how to proceed.
Comment #28
Dries CreditAttribution: Dries commentedI think the docgroup should paint a picture of the architecture/design so that people can easily understand the code. We shouldn't try answer all of the above questions IMO -- those are probably best answered in the handbook. However, the docgroup should set people up to read the code and to help them answer these questions. It's sort of a subtle difference.
Comment #29
webchickI guess that's a needs work.
Comment #30
sunHm. heheh... the core maintainer feedback leaves lots of room for interpretation. I guess it's neither the patch nor the proposal to explain all from high-level to low-level then. Rather, both, but differently. :-)
Therefore, remixing some answers to the questions with parts of the patch will likely lead to something committable.
Ideally, I think we should pull someone from the documentation team into this issue to find the right level of detail - as we all are more or less familiar with the system. (YMMV)
Comment #31
plachYes, we definitely need some hint on the direction to take here. The current patch tries to provide an architectural overview, but still keeping the description low level as yched asked in the OP. If that's somehow incorrect an example on how to improve it would be helpful.
Comment #32
plachI'm sorry but I have absolutely no clue about how to proceed here.
Comment #33
plachI'd say this needs to be done sooner or later.
Comment #34
yched CreditAttribution: yched commentedDoes it still apply ?
We're definitely better with than without this...
Comment #35
plachThe previous patch applied with some offset. Here is a reroll.
Comment #36
webchickI can't quite parse Dries's #28 either, but I think he's basically saying that docblocks don't need to answer all of the questions outlined in sun's #17. The handbook's a much better place for this kind of information, because we can elaborate, re-organize, pull in additional questions from comments, etc. See http://drupal.org/node/146843 and http://drupal.org/node/310069 for examples where we've done this.
As long as one of the TF maintainers still feels the docs in the patch are an accurate reflection of what TF does N months later, I'm happy to commit this patch.
Comment #37
plachI confirm the documentation in the patch is still up-to-date, but I'll leave someone else to RTBC it (again).
Comment #38
sunComment #39
webchickCommitted to HEAD. Thanks!
Comment #40
plachWhoo-hoo! :)
Comment #41
plachSmall follow-up: the Field language API should be cited in the main Field API documentation.
Comment #42
yched CreditAttribution: yched commentedMakes sense.
Comment #43
Dries CreditAttribution: Dries commentedCommitted to CVS HEAD. Thanks.