According to Gabor we absolutely need a language selection widget on every entity edit form. I think this might be problematic in some situations, e.g. when creating terms through a node taxonomy field, hence we need some kind of fall back strategy.

Files: 
CommentFileSizeAuthor
#13 et-language_widget-1280546-13.interdiff.do_not_test.patch2.99 KBplach
#13 et-language_widget-1280546-13.patch32.97 KBplach
PASSED: [[SimpleTest]]: [MySQL] 681 pass(es).
[ View ]
#11 et-language_widget-1280546-11.interdiff.do_not_test.patch8.89 KBplach
#11 et-language_widget-1280546-11.patch32.63 KBplach
PASSED: [[SimpleTest]]: [MySQL] 681 pass(es).
[ View ]
#10 et-language_widget-1280546-10.interdiff.do_not_test.patch15.31 KBplach
#9 et-language_widget-1280546-7.patch32.38 KBplach
PASSED: [[SimpleTest]]: [MySQL] 681 pass(es).
[ View ]
#7 et-settings-1280546.png25.12 KBbforchhammer
#5 et-language_widget-1280546-5.patch23.25 KBplach
PASSED: [[SimpleTest]]: [MySQL] 681 pass(es).
[ View ]
#4 et-language_widget-1280546-4.patch20.72 KBplach
PASSED: [[SimpleTest]]: [MySQL] 681 pass(es).
[ View ]
#3 et-language_widget-1280546-3.patch17.84 KBplach
PASSED: [[SimpleTest]]: [MySQL] 681 pass(es).
[ View ]

Comments

Component:Code» Base system
Assigned:Unassigned» plach

Working on this.

Status:Active» Needs review
StatusFileSize
new17.84 KB
PASSED: [[SimpleTest]]: [MySQL] 681 pass(es).
[ View ]

Here is a first attempt. To do:

  • Extra field language widget reordering.
  • Granular settings to display the language selection widget per entity bundle.
  • Granular settings for the default entity language.

Let's see if the bots complains.

StatusFileSize
new20.72 KB
PASSED: [[SimpleTest]]: [MySQL] 681 pass(es).
[ View ]

Implemented per-language settings. Only field reordering is missing.

StatusFileSize
new23.25 KB
PASSED: [[SimpleTest]]: [MySQL] 681 pass(es).
[ View ]

Et voilà. I think now we need only an update function to keep BC.

I'll try to test+review this soon... :)

Status:Needs review» Needs work
StatusFileSize
new25.12 KB

Patch #5 summary of changes:

  • It adds a "language selector" for all entities, e.g. comments, files (tested with file_entity), bean, ...
  • It adds new bundle-specific settings for a) setting the default language, and b) hiding the language selector.

This is the new settings screen:

The new settings are currently also applied to entities which have ET disabled! Is that intended?

Patch #5 code review

+++ b/entity_translation.admin.inc
@@ -57,6 +57,65 @@ function entity_translation_admin_form($form, $form_state) {
+  $et_settings = variable_get('entity_translation_settings', array());

I think that this variable should be split into separate entity_translation_settings_TYPE__BUNDLE variables; having only one variable makes it hard to e.g. export settings for only a few selected content types. There was a similar issue in core with the field_bundle_settings variable, see this change notice.

It would be cool if it was also possible to provide global or entity defaults, and override them on the bundle level. (Personally I'd probably almost always use "current language" and "show selector".) However, as far as I know core doesn't do something like this anywhere either, so definitely not required.

+++ b/entity_translation.admin.inc
@@ -57,6 +57,65 @@ function entity_translation_admin_form($form, $form_state) {
+    'xx-et-default' => t('Default language'),
+    'xx-et-current' => t('Current language'),
+    'xx-et-author' => t('Author language'),

The keys could (should?) be moved into constants so that we don't have to juggle strings...

+++ b/entity_translation.module
@@ -351,6 +352,10 @@ function entity_translation_menu_alter(&$items) {
+          if ($item['access callback'] == 'entity_translation_tab_access') {
+            $item['access arguments'][] = $entity_position;
+          }
@@ -642,8 +647,12 @@ function entity_translation_admin_paths() {
+function entity_translation_tab_access($entity_type, $entity) {
+  if (drupal_multilingual() && (user_access('translate any entity') || user_access("translate $entity_type entities"))) {
+    $handler = entity_translation_get_handler($entity_type, $entity);
+    return $handler->getLanguage() != LANGUAGE_NONE;
+  }
+  return FALSE;
+++ b/entity_translation.node.inc
@@ -65,7 +65,7 @@ function entity_translation_node_tab_access() {
+      return entity_translation_tab_access('node', $node);

Are these changes required for the language selector? What's their effect on the permissions tests in #1770750: Improve test coverage?.

+++ b/entity_translation.module
@@ -1222,8 +1259,16 @@ function _entity_translation_element_title_append(&$element, $suffix) {
+    // We need to process the posted form as early as possible to update the
+    // form language value.
+    array_unshift($form['#validate'], 'entity_translation_entity_form_validate');
+++ b/includes/translation.handler.inc
@@ -1003,10 +1058,6 @@ class EntityTranslationDefaultHandler implements EntityTranslationHandlerInterfa
-    // We need to process the posted form as early as possible to update the
-    // form language value.
-    array_unshift($form['#validate'], 'entity_translation_entity_form_validate');
-
     // Process entity form submission.
     $form['#submit'][] = 'entity_translation_entity_form_submit';

These changes make me wonder whether it would be good for developers to attach all ET form handlers in one place... so maybe we should also move the #submit handler into hook_form_alter()? Not sure.

+++ b/entity_translation.module
@@ -1470,7 +1523,8 @@ function entity_translation_language($entity_type, $entity) {
+ *   (optional) The entity to be translated. A bundle name may be passed to
+ *   instantiate an empty entity.

This change is causing notices with the bean module (bean translation handler), because it relies on having a properly loaded entity: Undefined property: stdClass::$delta in EntityTranslationBeanHandler->getEntityId() This will need a follow-up issue...

Maybe we should also add a respective comment to the handler interface docs, saying that the entity might only be a stub entity.

+++ b/includes/translation.handler.inc
@@ -837,6 +905,11 @@ class EntityTranslationDefaultHandler implements EntityTranslationHandlerInterfa
+    // Store the information about being editing the original values for later
+    // reuse: a language change might render impossibile to determine this
+    // otherwise.

Not sure what this comment is trying to tell me :)


@plach: great work on the patch! I can see the beta release coming closer and closer... :)

Another minor todo: the new entity_translation_settings variable should be deleted in hook_uninstall().

Status:Needs work» Needs review
StatusFileSize
new32.38 KB
PASSED: [[SimpleTest]]: [MySQL] 681 pass(es).
[ View ]

I think we should be ready to go now.

Er, I missed #7. Hopefully some of the issues were fixed by #9. Here is an interdiff.

Basically I added an update function and new entity info stuff to provide better BC. BTW now we have per-bundle translation.

StatusFileSize
new32.63 KB
PASSED: [[SimpleTest]]: [MySQL] 681 pass(es).
[ View ]
new8.89 KB

This plus #9 should fix #7 except for:

It would be cool if it was also possible to provide global or entity defaults, and override them on the bundle level.

Makes sense but I'd leave that for a follow-up. This patch is already doing too much ;)
Btw I want also the other settings (fallback, ...) to be per-bundle.

Are these changes required for the language selector? What's their effect on the permissions tests in #1770750: Improve test coverage?.

Well, yes, now we can assign LANGUAGE_NONE to any entity type so we have to account for that when deciding whether displaying the translate tab.

These changes make me wonder whether it would be good for developers to attach all ET form handlers in one place... so maybe we should also move the #submit handler into hook_form_alter()? Not sure.

Well, the validation handler is a hack and is really hardcoded logic, while the submission handlers should be overridable, if needed, by the specialized translation handlers. I'd leave this as is.

Maybe we should also add a respective comment to the handler interface docs, saying that the entity might only be a stub entity.

Not sure where, honestly.

I want to merge my topic branch so please don't commit any patch here.

StatusFileSize
new32.97 KB
PASSED: [[SimpleTest]]: [MySQL] 681 pass(es).
[ View ]
new2.99 KB

Last one: fixed a bug introduced by #11 and adds an option to exclude LANGUAGE_NONE from the available languages.

Just posted a new patch in #1495570: Update Entity translation integration which relies on this. It would be good to commit this and then get it RTBC ASAP, since the new Commerce release should be out on October 5th. Testing the patch spawned a couple of new issues:

#1798456: Hide shared form elements when the user has not the related permission
#1798460: Make the translate operation contextual

Status:Needs review» Reviewed & tested by the community

Awesome! Patch looks good to me.

Minor documentation issues:

+++ b/includes/translation.handler.inc
@@ -837,6 +907,12 @@ class EntityTranslationDefaultHandler implements EntityTranslationHandlerInterfa
+    // might render impossibile to make this check after form submission we

"Impossible" has an "i" too much.

+++ b/entity_translation.module
@@ -9,6 +9,25 @@ module_load_include('inc', 'entity_translation', 'entity_translation.node');
+/**
+ *
+ * @var unknown_type
+ */
+define('ENTITY_TRANSLATION_LANGUAGE_CURRENT', 'xx-et-current');

I think these doc blocks can be removed. ;)

Status:Reviewed & tested by the community» Fixed

Fixed #15, committed and pushed, thanks!

Now we should really focus on getting #1495570: Update Entity translation integration RTBC :)

Issue tags:+Needs tests

This will need test coverage.

Follow-up issue for bean module: #1799776: Fix entity translation regressions

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