How to react on entity translation insert/update/delete?

Is there a plan to implement a hook_entity_translation_insert(), hook_entity_translation_update(), hook_entity_translation_delete()?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

plach’s picture

Good point, this seems a sensible request: no plan atm, but this should not be hard to implement. Patches welcome.

plach’s picture

plach’s picture

Title: Reacting on translation update » Introduce entity translation CRUD hooks
Component: Code » Base system
bforchhammer’s picture

I just had a quick look at this, and I'm wondering whether hooks should be called when the handler object is updated (i.e. setTranslation, removeTranslation methods), or before/after data is actually stored in the database (i.e. saveTranslations method)... Thoughts?

plach’s picture

From the top of my head I'd say after the values are stored, but I did not have the chance to wrap my mind around this yet.

bforchhammer’s picture

Attached is a quick first stab at a patch... probably needs work.

bforchhammer’s picture

Status: Active » Needs review
FileSize
2.94 KB

Same as #6 with less errors in docs.

plach’s picture

Thanks, seems like a good start!

What about passing entity and entity type instead of the handler? This would look more consistent with the core entity hooks and the handler could be retrieved by using those two if needed.

bforchhammer’s picture

Yes, I also just realized that entity-related info was kind-of missing ;-)

plach’s picture

Status: Needs review » Reviewed & tested by the community

Awesome, thanks.

Feel free to commit #9.

bforchhammer’s picture

Status: Reviewed & tested by the community » Fixed

Thanks. Committed & pushed :)

plach’s picture

Status: Fixed » Needs review
FileSize
5.59 KB
9.24 KB

I just realized hooks are fired before translation are stored. This is not consistent with the entity CRUD hooks. Here's a patch + tests to fix this.

Status: Needs review » Needs work

The last submitted patch, et-hooks-1224590-12.test.patch, failed testing.

plach’s picture

Status: Needs work » Needs review
plach’s picture

FileSize
11.68 KB

Improved tests.

plach’s picture

FileSize
11.68 KB
+++ b/tests/entity_translation.test
@@ -283,3 +284,117 @@ class EntityTranslationTranslationTestCase extends EntityTranslationTestCase {
+  function atestFormWorkflow() {

Fixed this development leftover. This looks good to go now, I will commit it soon. Reviews welcome meanwhile.

plach’s picture

Status: Needs review » Fixed

Committed and pushed.

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

  • Commit f267ca3 on 7.x-1.x, et-permissions-1829630, factory, et-fc, revisions by bforchhammer:
    Issue #1224590 by bforchhammer: Added entity translation CRUD hooks.
    
  • Commit 15cdbfa on 7.x-1.x, et-permissions-1829630, factory, et-fc, revisions by plach:
    Issue #1224590 by plach: Made entity translation CRUD hooks fire only...

  • Commit f267ca3 on 7.x-1.x, et-permissions-1829630, factory, et-fc, revisions, workbench by bforchhammer:
    Issue #1224590 by bforchhammer: Added entity translation CRUD hooks.
    
  • Commit 15cdbfa on 7.x-1.x, et-permissions-1829630, factory, et-fc, revisions, workbench by plach:
    Issue #1224590 by plach: Made entity translation CRUD hooks fire only...