I'm using the Deploy module along with UUID to export entities into features. I've found out that entities are exported with their translations, which is great. However, when I wanted to reimport them, I found out that the import did not work. I therefore created a patch which fixes it, and removes some fields from the export.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

guillaumev’s picture

Status: Active » Needs review
FileSize
1.08 KB

Here is the patch...

guillaumev’s picture

FileSize
1.09 KB

New patch, which also removes uid from the list of exported fields.

plach’s picture

Status: Needs review » Needs work
+++ b/entity_translation.module
@@ -94,6 +94,29 @@ function entity_translation_language_types_info_alter(array &$language_types) {
+  $fields = array('entity_type', 'entity_id', 'uid', 'created', 'changed');

Why do we need to remove all those keys?

+++ b/entity_translation.module
@@ -94,6 +94,29 @@ function entity_translation_language_types_info_alter(array &$language_types) {
+  if (isset($entity->translations) && isset($entity->translations->data)) {

Here and below: use the entity translation handler to retrieve translations as they might not always be stored in the translations key.

guillaumev’s picture

FileSize
1.36 KB

Thanks for the review :-)

Concerning the keys:

  • entity_type can be removed since the translations is attached to the entity, so the entity_type can be determined (and is determined)
  • entity_id needs to be removed because it will change from one site to another
  • uid needs to be removed because it will change as well from one site to another
  • created and changed could eventually be left, but the uuid module removed created and changed from the entities it exports, so I figured I would do the same...

Concerning the use of the entity translation handler, here is a new patch that uses it.

guillaumev’s picture

Status: Needs work » Needs review
plach’s picture

Status: Needs work » Needs review

Thanks for the explanation, actually removing 'created' and 'changed' looked a bit odd to me. They concern creating/changing the translation, not the main entity so I guess it would be useful to keep them. Not a key point however.

Not sure why, but in the export hook we are using the translation handler while in the presave one we are using the entity keys directly. For consistency we should be using the translation handler in both places, moreover subclasses might change its default behavior and not rely on the entity keys. I know it's unlikely, but better safe than sorry :)

plach’s picture

Status: Needs review » Needs work
guillaumev’s picture

Status: Needs review » Needs work

Thanks for your follow up, but how can I use the translation handler to cast the "translations" array into an object ? I couldn't find this possibility in the translation handler, that's why I used the entity key directly...

plach’s picture

Why do you need that cast? The $translations data structure should already be an object. If this is absolutely needed let's go with this approach, but it looks weird to me. At very least we should add a comment explaining what's going on.

guillaumev’s picture

uuid exports entities as arrays. Here is an excerpt from the uuid export code:

// Convert entities to array to avoid having them in JSON, returned from standard implementation of $entity->export().
if (is_object($entity) && method_exists($entity, 'export')) {
  $entity = get_object_vars($entity);
}
$code[] = '  $entities[\'' . check_plain($component) . '\'][] = (object) ' . features_var_export($entity, '  ') . ';';

The translations object therefore becomes an array in the feature, that's why I need to cast it into an object before it is saved with uuid, otherwise there is an error.

Attached is a new patch which adds a comment to explain what's going on.

plach’s picture

+++ b/entity_translation.module
@@ -94,6 +94,38 @@ function entity_translation_language_types_info_alter(array &$language_types) {
+ * Implements hook_uuid_entities_features_export_entity_alter()
...
+ * Implements hook_entity_uuid_presave()

Missing trailing dot.

+++ b/entity_translation.module
@@ -94,6 +94,38 @@ function entity_translation_language_types_info_alter(array &$language_types) {
+function entity_translation_uuid_entities_features_export_entity_alter(&$entity, $entity_type) {
...
+function entity_translation_entity_uuid_presave(&$entity, $entity_type) {

$entity is an object, right? It shouldn't be needed to pass it by reference in this case.

+++ b/entity_translation.module
@@ -94,6 +94,38 @@ function entity_translation_language_types_info_alter(array &$language_types) {
+ * ¶

Trailing whitespace.

+++ b/entity_translation.module
@@ -94,6 +94,38 @@ function entity_translation_language_types_info_alter(array &$language_types) {
+ * uuid exports entities as arrays, therefore we need to cast the translations
+ * array back into an object

Can we have UUID all uppercase to improve readbility? Also, trailing dot missing.

Edit: That comment should be in the function body, it's not a PHP doc.

guillaumev’s picture

Status: Needs work » Needs review
FileSize
1.47 KB

New patch, with corrections and which works with the latest dev version.

plach’s picture

Status: Needs review » Reviewed & tested by the community

Wonderful, thanks.

Actually I just realized that also the explanation in #4 could be translated in a comment, but I'll do that myself when committing.

plach’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed, thanks.

guillaumev’s picture

Thanks, but just for next time: http://drupal.org/node/1146430 :-)

plach’s picture

Yeah, sorry, I usually do that, this time I just forgot it :(

jonhattan’s picture

Category: feature » bug
Priority: Normal » Major
Status: Fixed » Active
Issue tags: +D7 stable release blocker

For entity types without entity_translation enabled, there's a fatal error:

PHP Fatal error: Cannot access empty property in entity_translation/includes/translation.handler.inc on line 603

This is part of the backtrace:

21: EntityTranslationDefaultHandler->setEntity() 
20: EntityTranslationDefaultHandler->__construct()
19: EntityTranslationBeanHandler->__construct()
18: entity_translation_get_handler()
17: entity_translation_uuid_entities_features_export_entity_alter()
16: drupal_alter()
15: uuid_entities_features_export_render()
14: call_user_func_array()
13: features_invoke()
12: features_get_normal()
11: features_get_signature()
10: features_get_component_states()

Note: this is not bean specific. For exported nodes:

19: EntityTranslationNodeHandler->__construct() 
jonhattan’s picture

Status: Active » Needs review
FileSize
1.29 KB

Here's a fix

plach’s picture

Thanks, but why are we skipping the field handler check?

jonhattan’s picture

The path to the fatal error pass by 18: entity_translation_get_handler()

plach’s picture

jonhattan’s picture

Oh I'm sorry. I'm not familiar with entity_translation internals. Just copied the like from the implementation of hook_info_alter().

New patch without skipping the field handler check. It also works for my setup.

plach’s picture

Status: Needs review » Reviewed & tested by the community

Thanks!

bforchhammer’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed :)

plach’s picture

Category: bug » feature
Issue tags: -D7 stable release blocker
plach’s picture

Priority: Major » Normal

@bforchhammer:

The change log entry is missing :)

bforchhammer’s picture

@plach: oops, sorry, changelog entry added :)

Status: Fixed » Closed (fixed)

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

  • Commit 5a2e978 on 7.x-1.x, et-permissions-1829630, factory, et-fc, revisions by plach:
    Issue #1701212 by guillaumev: Added Export entity translations using...
  • Commit 57a23c8 on 7.x-1.x, et-permissions-1829630, factory, et-fc, revisions authored by jonhattan, committed by bforchhammer:
    Issue #1701212 by jonhattan: Fixed fatal error for entities with ET...

  • Commit 5a2e978 on 7.x-1.x, et-permissions-1829630, factory, et-fc, revisions, workbench by plach:
    Issue #1701212 by guillaumev: Added Export entity translations using...
  • Commit 57a23c8 on 7.x-1.x, et-permissions-1829630, factory, et-fc, revisions, workbench authored by jonhattan, committed by bforchhammer:
    Issue #1701212 by jonhattan: Fixed fatal error for entities with ET...