Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
We've had at least 2 occasions where we needed to intervene within this function (once for ERS, and also for UUID). Would it make sense to add a hook here? That clone operation has also caused problems, because not all attributes should be automatically inherited from the source node to the translated one.
Comment | File | Size | Author |
---|---|---|---|
#12 | tmgmt-new_node_source_alter-1673904-12.patch | 1.41 KB | seanB |
#6 | tmgmt-new-node-source-alter-1673904-0.patch | 1.96 KB | ethanethan |
Comments
Comment #1
BerdirYes, adding a hook sounds fine, patch? :) Remember to also add a .api.php file and documentation for that hook inside it, see the current entity source overview patch for an example.
Comment #2
ethanethan CreditAttribution: ethanethan commentedOk, i'll give it a shot!
Comment #3
ethanethan CreditAttribution: ethanethan commentedSimilar to the TMGMT checkout hooks, should i add one at the beginning of saveTranslation and then right before update_node_translation? Not sure how to do this, since i need to specify a different $tnode, but also need to get in the if (empty($node->tnid)) block.
Comment #4
BerdirOne hook sounds good enough for me for the moment. $tnode is by reference, so you could completely replace the object if you want to. If there is only one thing in $data, you can just as well pass $job_item directly as the third argument.
Comment #5
ethanethan CreditAttribution: ethanethan commented(i had two actually, just removed $translation since the results are cached and i can run it again!)
Yup i'm replacing $tnode for sure. The issue is with the node_save on the source node (in the empty($node->tnid) block). I need to set something for ERS at that point, and after tnid is set, i can't seem to filter for it anymore.
Comment #6
ethanethan CreditAttribution: ethanethan commentedOk, here's the hook and the documentation. Let me know what you think.
Comment #7
ethanethan CreditAttribution: ethanethan commentedComment #8
BerdirThe hook looks ok, some coding style issues to be fixed:
Make sure that comments aren't longer than 80 characters, most editors provide a setting to show where the 80 character line is. In this case, exactly both last words are too long.
First line should be a short description of what the hook allow to do
"Alter the created node translation."
The description of a @param should be on the next line, intended by 2 spaces more than @param. Also, the comment should start with an uppercase character and end with a ".".
Typo ("Exmample").
I don't understand what your example is doing, it completely replaces our generated node object without adding the new translations? That makes no sense.
Comment #9
ethanethan CreditAttribution: ethanethan commentedFor the example, let me try to explain! The original implementation in TMGMT just loads an existing translation:
$tnode = node_load($translations[$job->target_language]->nid);
and then resaves the data within this one. We needed a way to revision translations, so i cloned the existing one instead (similar to how TMGMT does it for a new translation) and set its revision property. The hook comes before the actual saving, so yes i replace the target tnode. Is there a better way to do this? Or maybe i should just change the example?
Comment #10
BerdirYes, I understand what you are trying to do. But at least the example code is missing the most important part... assigning the new translations. All that the code is doing is saving the original, previous translation as a new revision, completely ignoring the new translation. Then there's that useless clone, you could just overwrite the original variable initially.
Let's go for a very simple example instead, I suggest just something like this:
Comment #11
ethanethan CreditAttribution: ethanethan commentedOh. Well thats a much simpler way to do the same thing, isnt it.
Comment #12
seanBI updated the patch in #6 to work with the latest version of the module and processed the comments. Could you review this?
Comment #13
BerdirWorks for me. Couldn't apply the patch with git, it didn't understand that tmgmt_node.api.php is a new file, but patch -p1 worked.
Thanks!
8.x-1.x doesn't have tmgmt_node, but the same hook in the content translation module would make sense as well.
Comment #15
gaurav_manerkar CreditAttribution: gaurav_manerkar at EPAM Systems commentedHi,
Is there any plan to rollout the patch for 8x version ?