hook_field_languages [see function field_multilingual_available_languages() in modules/field/field.multilingual.inc]

Part of #675046: Make sure all hooks in D7 have documentation

CommentFileSizeAuthor
#5 776982.patch1.22 KBrobeano

Comments

robeano’s picture

Actually, modules/field/field.multilingual.inc has changed a little. It looks like there are two alters now:

hook_field_available_languages_alter() called in field_available_languages()

and

hook_field_language_alter() called in field_language()

I will document both.

robeano’s picture

Oops. My mistake...I missed the module_implements(), and it really is in field_multilingual_available_languages(). Please disregard comment #776982-1: hook_field_languages() is not documented

puregin’s picture

Status: Active » Fixed

It looks like this was fixed at some point. I updated the description for both hook_field_language_alter() and hook_field_available_languages_alter() in field.api.php in the course of cleanup for issue #776694: hook_field_attach_purge is not documented.

Marking as fixed...

robeano’s picture

Status: Fixed » Active

This isn't fixed. hook_field_languages() has not been documented yet. I am working on a patch now.

robeano’s picture

StatusFileSize
new1.22 KB

Patch provides documentation for hook_field_languages. Ready for review.

robeano’s picture

Status: Active » Needs review

Darn it. I forgot to change the status.

Status: Needs review » Needs work

The last submitted patch, 776982.patch, failed testing.

jhodgdon’s picture

Status: Needs work » Needs review

#5: 776982.patch queued for re-testing.

jhodgdon’s picture

Status: Needs review » Needs work

Those test failures are not caused by this patch.

Reviewing the patch...
$language is defined as:

"An array of language preferences which will be intersected with the enabled languages."

I don't know what this means. Are they strings, or language objects? What does intersected mean? And the example function body has a comment saying an unavailable language is added -- what will that do if there is some kind of intersection with available languages?

Also, a puncuation note: you need a comma before a "which". :)

blg@bgreenaway.com’s picture

jhodgdon, the $languages detail is too specific here, right?

Array intersection is merely one thing that could be performed by this hook, but seems by no means required.

Trivially, having data passed in to a custom function merely makes it available to that function for working with (or perhaps operating on, but that should be handled under an hook_alter method.) Intersection would give you a common denominator of equally set values ignoring ones unique to a single language, but the hook _could_ do other things, like color code everything blue if Chinese translation is set for Mandarin rather than Wu...?

Point's not that $languages will be intersected and what happens if (eg the expected return of the intersected array objects) but that $languages is being passed into the function body and the docs should say what it is.

So I think it will be sufficient to write,
+ * @param $languages
+ * An array of language preferences.
or maybe
+ * @param $languages
+ * The complete array of language preference settings for your site.
(if indeed it is)

Again, sorry I can't make/attach my suggested patch but this would take longer than this posting and might delay the fix. (I'll check back later when I've worked out a patch build process.)

jhodgdon’s picture

Status: Needs work » Fixed

That comment on #1 is correct -- hook_field_languages() doesn't appear to exist, nor does the function that used to invoke it.

So, this is no longer an issue. The other two hooks identified in #1 have already been documented.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.