Updated: Comment #5
Problem/Motivation
The current Field Language API is completely obsoleted by the new Entity Field API and in particular the new API for entity translation.
Proposed resolution
This was discussed in Prague and there was consensus that once we are done with #2019055: Switch from field-level language fallback to entity-level language fallback and field_method_invoke()/field_method_invoke_multiple() functions are gone, we can safely get rid of field.multilingual.inc altogether.
[edit: field_method_invoke_*() are still there atm but have been cleaned out of their "old field multilingual logic" in #1988612: Apply formatters and widgets to rendered entity base fields, starting with node.title, so they are not blockers anymore]
The discussion was attended by: attrib, berdir, das_peter, fago, Gábor Hojtsy, plach, swentel, tstoeckler, webflo, yched.
Remaining calls
Remaining calls (not counting functions calling each other):
field_language() :
- field_get_items(): already deprecated, and was really related to the old "$node->field_foo[$langcode]" syntax, so should be removed here as well.
- field_view_field() / field_view_value()
- a couple docs / @see here and there.
field_valid_language()
- none after #2155665: Update field_valid_language() calls in edit.module
field_available_languages() / hook_field_available_languages()
- a couple tests
_field_language_suggestion()
- none
field_content_languages()
- a test
field_is_translatable()
- none after #2018685: Remove field_is_translatable()
field_has_translation_handler()
- just a stale static in field_test_entity_info_translatable()
User interface changes
None
API changes
The whole Field Language API will be deprecated/removed.
Related Issues
#2019055: Switch from field-level language fallback to entity-level language fallback
#2018685: Remove field_is_translatable()
Original report by @yched
field.multilingual.inc has a couple functions, that predate the new API for entity translation.
They are most likely deprecated at best, obsolete/wrong at worst, but I'm not fully familiar with the new Entity translation API and code, nor with the code in that field.multilingual.inc file even in D7.
In other words: feedback and help welcome from @plach / @Gabor / @fago :-)
At least it seems that since base fields can be translatable too, those functions have no business
a) being in field.module
b) dealing with "configurable fields" only
- field_available_languages()
"Collects the available language codes for the given entity type and field" - field_content_languages()
"Returns available content language codes" - field_language_fallback_enabled()
"Checks whether field language fallback is enabled" - field_is_translatable()
"Checks whether a field has language support" - field_has_translation_handler()
"Checks if a module is registered as a translation handler for a given entity" - field_valid_language()
"Ensures that a given language code is valid" - field_language()
"Returns the display language code for the fields attached to the given entity" - field_language_fallback()
"Applies language fallback rules to the fields attached to the given entity"
| Comment | File | Size | Author |
|---|---|---|---|
| #32 | 2067079-field-mlang-32.patch | 22.07 KB | andypost |
Comments
Comment #1
yched commentedAdded field.module's field_language_fallback()
Comment #1.0
yched commentedmore details
Comment #2
amateescu commentedSome of this is touched by #2019055: Switch from field-level language fallback to entity-level language fallback so I guess we need to wait a bit and see what's left to clean up after.
Comment #2.0
plachAdded field_language_fallback()
Comment #3
plachThis is meaningfully used only by
field_invoke_method/field_invoke_method_multiple, where I think we can safely replace it with an inline check for field translatability +EntityInterface::getTranslationLanguages(). My current feeling is that the whole D7 approach of dealing with language at field level is obsolete in D8, where we have the notion of entity translation. Once we are able to move all thefield_attach_*functions to entity controllers, we should no longer need to know field language in most scenarios.I think it should be safe to remove the alter hook as the main use case behind it was supporting language of parts, which @fago suggested to support through a dedicated field item property.
This can be safely replaced by a call to
language_list(Language::STATE_ALL), which is how it is currently implemented in D8 btw.Deprecated in #2019055: Switch from field-level language fallback to entity-level language fallback.
Since we no longer have the notion of translation handler, we can simply rely on the
'translatable'property of the field definition. We have an issue for the details: #2018685: Remove field_is_translatable().Totally obsolete, it should already be deprecated. To be removed ASAP.
A small utility function which should turn less and less useful as soon as the migration to the Entity Field API proceeds.
Deprecated in #2019055: Switch from field-level language fallback to entity-level language fallback.
Deprecated in #2019055: Switch from field-level language fallback to entity-level language fallback.
Comment #3.0
plachUpdated issue summary.
Comment #4
yched commentedThanks @plach!
So yeah, we'll wait on #2019055: Switch from field-level language fallback to entity-level language fallback to deprecate more stuff and then see whether we can clean the remaining field_attach_*() functions (#1497374: Switch from Field-based storage to Entity-based storage removes a couple more of those)
Comment #5
plachComment #5.0
plachfield_language_fallback() has been moved to field.multilingual.inc
Comment #5.1
plachUpdated issue summary.
Comment #6
plachWe need to fix the OP issues first. Rolling a patch should be fairly easy at the point.
Comment #7
plachMore tags
Comment #7.0
plachAdded issue summary.
Comment #8
effulgentsia commentedUnpostponing now that #2019055: Switch from field-level language fallback to entity-level language fallback is in.
Comment #9
plachSorry, but I think we should wait for #2095195: Remove deprecated field_attach_form_*() too :(
Comment #10
yched commentedWe'll be trying to get #1988612: Apply formatters and widgets to rendered entity base fields, starting with node.title in before #2095195: Remove deprecated field_attach_form_*() lands, and it *might* be possible to get rid of most of the old field_language* calls in there already. Not fully sure yet.
Comment #11
plachOk, let's wait for #1988612: Apply formatters and widgets to rendered entity base fields, starting with node.title then.
Comment #12
yched commentedSo yes, latest patch in #1988612: Apply formatters and widgets to rendered entity base fields, starting with node.title removes the field_language*() calls in field_invoke_method*(). Which should get rid of most (if not all, didn't check) the remaining calls to the old field multilingual logic.
Comment #13
yched commentedWe really want to clean that up before beta.
The old multilingual logic is completely outdated, and keeping it there simply muddies the waters.
Comment #14
yched commentedRemaining calls (not counting functions calling each other):
field_language() :
- field_get_items(): already deprecated, and was really related to the old "$node->field_foo[$langcode]" syntax, so should be removed here as well.
- field_view_field() / field_view_value(): being taken care of in #2134887: move field_view_field() / field_view_value() to methods
- a couple docs / @see here and there.
field_valid_language()
- Drupal/edit/EditController, Drupal/edit/Access/EditEntityFieldAccessCheck
opened #2155665: Update field_valid_language() calls in edit.module
field_available_languages() / hook_field_available_languages()
- a couple tests
_field_language_suggestion()
- none
field_content_languages()
- a test
field_is_translatable()
discussed in #2018685: Remove field_is_translatable()
field_has_translation_handler()
- just a stale static in field_test_entity_info_translatable()
Bumped the mentioned issues to "beta target" as well.
Comment #15
plachTotally agreed on the beta target tag.
So, if I understand this right, we are going to remove everything here aside from the linked issues, correct?
Comment #16
yched commentedWell, since all those functions call each other, it's hard to start removing some until there is still external code that calls some of them.
So I was rather thinking that all the linked issues would need to be adressed first so that there's no external callers, and then we can remove the functions here ?
Comment #17
plachYup, that was more or less what I thought.
Comment #18
wim leers#2155665: Update field_valid_language() calls in edit.module now has a patch — please review so this issue gets unblocked :)
Comment #19
yched commentedMoved the list in #14 to the issue summary.
Comment #20
yched commented#2155665: Update field_valid_language() calls in edit.module is in, so taking a crack at this.
- Patch includes #2018685: Remove field_is_translatable() for now.
- #2134887: move field_view_field() / field_view_value() to methods is taking a little time, so converting the field_language() calls here.
Comment #23
yched commentedBleh, wrong method name.
TranslationWebTest still has warnings, it seems that ContentEntityBase::getTranslationLanguages() hits cases where $this->translations has entries where $translation['status'] is not set.
@plach: help welcome here :-)
Comment #25
yched commentedReroll after #2018685: Remove field_is_translatable()
Comment #27
yched commentedOK, this should be ready except for those 3 remaining notices for which I'd need help from entity / language folks :-)
(see #23 for details)
Comment #28
yched commentedComment #29
yched commentedComment #30
plachI'll have a look to them tonight :)
Comment #31
andypostThis test is broken because
getTranslationLanguages()returns actual languages that entity contain, and there's no alter hook that was used to add additional languagesComment #32
andypostFix last test, RTBC +1
Comment #33
effulgentsia commentedThis looks good to me as well, but leaving to plach to RTBC, or at least +1.
Comment #34
plachLooks great, thanks!
All the old function usages are converted to the new API and the removed test is just obsolete now: the new logic is already covered by the Entity Translation API tests.
The removed hook was never used AFAIK, as no UI was implemented in contrib to support language of parts. Moreover in Prague we agreed that to support that a composite field carrying the field content language would be better suited.
Comment #35
effulgentsia commentedRaising to beta blocker per #2061107-9: Remove deprecated procedural functions in Field API, since this is a requirement for it. Note that this patch actually does remove the field_language() and field_valid_language() functions, counter to the request in #2061107-9: Remove deprecated procedural functions in Field API, but:
a) The patch that got RTBC'd was posted here prior to that request, and
b) I don't know if it's possible to leave these functions in as wrappers to anything and have them be functional in a way that a caller would expect, since the entire concept of these functions is nonsensical with D8's entity translation API.
Comment #36
webchickYeah, that seems fine. There's no point in leaving two competing translation systems in, deprecated or no.
Committed and pushed to 8.x. Thanks!
This will need a change notice.
Comment #37
plachUpdated the Entity Translation API change notice with a section on replacing the D7 API:
https://drupal.org/node/2040323#field-language-api
Comment #38
gábor hojtsyLooks good to me.