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.

#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"
Files: 
CommentFileSizeAuthor
#32 2067079-field-mlang-32.patch22.07 KBandypost
PASSED: [[SimpleTest]]: [MySQL] 60,065 pass(es).
[ View ]

Comments

yched’s picture

Added field.module's field_language_fallback()

yched’s picture

Issue summary:View changes

more details

amateescu’s picture

Status:Active» Postponed

Some 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.

plach’s picture

Issue summary:View changes

Added field_language_fallback()

plach’s picture

Title:field.multilingual.inc is obsolete ?» Deprecate/remove the Field Language API
Issue tags:+translatable fields

field_available_languages()
"Collects the available language codes for the given entity type and field"

This 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 the field_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.

field_content_languages()
"Returns available content language codes"

This can be safely replaced by a call to language_list(Language::STATE_ALL), which is how it is currently implemented in D8 btw.

field_language_fallback_enabled()
"Checks whether field language fallback is enabled"

Deprecated in #2019055: Switch from field-level language fallback to entity-level language fallback.

field_is_translatable()
"Checks whether a field has language support"

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().

field_has_translation_handler()
"Checks if a module is registered as a translation handler for a given entity"

Totally obsolete, it should already be deprecated. To be removed ASAP.

field_valid_language()
"Ensures that a given language code is valid"

A small utility function which should turn less and less useful as soon as the migration to the Entity Field API proceeds.

field_language()
"Returns the display language code for the fields attached to the given entity"

Deprecated in #2019055: Switch from field-level language fallback to entity-level language fallback.

+ in field.module: field_language_fallback()
"Applies language fallback rules to the fields attached to the given entity"

Deprecated in #2019055: Switch from field-level language fallback to entity-level language fallback.

plach’s picture

Issue summary:View changes

Updated issue summary.

yched’s picture

Thanks @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)

plach’s picture

Issue tags:+Prague Hard Problems
plach’s picture

Issue summary:View changes

field_language_fallback() has been moved to field.multilingual.inc

plach’s picture

Issue summary:View changes

Updated issue summary.

plach’s picture

We need to fix the OP issues first. Rolling a patch should be fairly easy at the point.

plach’s picture

Issue tags:+D8MI, +language-content

More tags

plach’s picture

Issue summary:View changes

Added issue summary.

effulgentsia’s picture

Issue summary:View changes
Status:Postponed» Active
plach’s picture

Sorry, but I think we should wait for #2095195: Remove deprecated field_attach_form_*() too :(

yched’s picture

We'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.

plach’s picture

yched’s picture

So 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.

yched’s picture

Priority:Normal» Major
Issue tags:+beta target

We really want to clean that up before beta.
The old multilingual logic is completely outdated, and keeping it there simply muddies the waters.

yched’s picture

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(): 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.

plach’s picture

Totally 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?

yched’s picture

Well, 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 ?

plach’s picture

Status:Active» Postponed

Yup, that was more or less what I thought.

Wim Leers’s picture

#2155665: Update field_valid_language() calls in edit.module now has a patch — please review so this issue gets unblocked :)

yched’s picture

Issue summary:View changes

Moved the list in #14 to the issue summary.

yched’s picture

Status:Postponed» Needs review
StatusFileSize
new26.93 KB
FAILED: [[SimpleTest]]: [MySQL] 59,952 pass(es), 1 fail(s), and 0 exception(s).
[ View ]

#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.

Status:Needs review» Needs work

The last submitted patch, 20: field_multilingual-2067079-19.patch, failed testing.

Status:Needs review» Needs work

The last submitted patch, 20: field_multilingual-2067079-19.patch, failed testing.

yched’s picture

Status:Needs work» Needs review
StatusFileSize
new26.94 KB
FAILED: [[SimpleTest]]: [MySQL] 59,806 pass(es), 0 fail(s), and 3 exception(s).
[ View ]
new872 bytes

Bleh, 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 :-)

The last submitted patch, 23: field_multilingual-2067079-23.patch, failed testing.

yched’s picture

StatusFileSize
new22.04 KB
FAILED: [[SimpleTest]]: [MySQL] 60,064 pass(es), 0 fail(s), and 3 exception(s).
[ View ]

Status:Needs review» Needs work

The last submitted patch, 25: field_multilingual-2067079-25.patch, failed testing.

yched’s picture

Title:Deprecate/remove the Field Language API» Remove the Field Language API

OK, this should be ready except for those 3 remaining notices for which I'd need help from entity / language folks :-)
(see #23 for details)

yched’s picture

Issue summary:View changes
yched’s picture

Issue summary:View changes
plach’s picture

I'll have a look to them tonight :)

andypost’s picture

+++ b/core/modules/field/lib/Drupal/field/Tests/TranslationWebTest.php
@@ -103,7 +103,7 @@ function testFieldFormTranslationRevisions() {
-    $available_langcodes = array_flip(field_available_languages($this->entity_type, $this->field));
+    $available_langcodes = array_keys($entity->getTranslationLanguages());

This test is broken because getTranslationLanguages() returns actual languages that entity contain, and there's no alter hook that was used to add additional languages

andypost’s picture

Status:Needs work» Needs review
StatusFileSize
new917 bytes
new22.07 KB
PASSED: [[SimpleTest]]: [MySQL] 60,065 pass(es).
[ View ]

Fix last test, RTBC +1

effulgentsia’s picture

This looks good to me as well, but leaving to plach to RTBC, or at least +1.

plach’s picture

Status:Needs review» Reviewed & tested by the community

Looks 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.

effulgentsia’s picture

Raising 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.

webchick’s picture

Title:Remove the Field Language API» Change notice: Remove the Field Language API
Status:Reviewed & tested by the community» Active
Issue tags:+Needs change record

Yeah, 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.

plach’s picture

Status:Active» Needs review

Updated the Entity Translation API change notice with a section on replacing the D7 API:

https://drupal.org/node/2040323#field-language-api

Gábor Hojtsy’s picture

Title:Change notice: Remove the Field Language API» Remove the Field Language API
Status:Needs review» Fixed
Issue tags:-Needs change record

Looks good to me.

Status:Fixed» Closed (fixed)

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