Needs work
Project:
Translation Management Tool
Version:
8.x-1.x-dev
Component:
Core
Priority:
Normal
Category:
Feature request
Assigned:
Reporter:
Created:
12 Nov 2015 at 14:44 UTC
Updated:
26 Feb 2016 at 07:39 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
ademarco commentedComment #3
ademarco commentedComment #4
ademarco commentedBadly rolled-out patch, I'll re-post!
Comment #5
ademarco commentedComment #6
berdirOK with adding such a hook in general. We did implement an escape API at some point, but it's not widely used. See the locale source for an example.
I think the hook name would make more sense without the get, just tmgmt_field_source_data?
Wondering if it wouldn't make more sense to alter the entity afterwards? maybe both?
Comment #7
ademarco commentedThanks for the quick feedback! I'd propose the following hooks then:
If ok I can re-roll the patch.
Comment #8
berdirFirst, something that I just forgot. drupal_alter() only supports 3 arguments.. the main thing to be altered and two contexts. Given that, I would recommend that you put all three additional arguments into a single $context array.
Second, I think for post we should switch the $data and $entity aguments then. It makes no sense to alter $data in post_populate as it has no effect. Instead, you want to alter the entity. And the thing that should be altered is always the first in alter hooks.
Comment #9
ademarco commentedActually drupal_alter() supports 4 arguments:
Although documentation says:
Shall we drop it?
About your second comment: sure, I'll switch the two first args as you suggested!
Comment #10
berdirAh, right, the third argument was added at some point because there were calls with 3 contexts in core and that was the easiest way to fix it.
8.x will look very different anyway, for starters, we don't need a $entity_type variable and likely also can skip the $langcode so we don't have to worry about that.
Comment #11
ademarco commentedRe-rolled including latest feedback, we should also provide some tests for the added functionality: which tests would you recommend me to look at in order to start working on it?
Comment #12
ademarco commentedComment #13
ademarco commentedRe-rolling since it was altering the wrong "$data".
Comment #14
ademarco commentedActually
hook_tmgmt_field_pre_populate_entity_alter()on we want still to alter $data and not $entity, I've rerolled the patch by switching the order of the two arguments.Comment #15
berdirThanks, committed and pushed. Moving to 8.x-1.x to evaluate if this is useful there too.
Comment #17
miro_dietikerI also was thinking about this and if it makes sense to add it.
However the example you provide sounds odd to me:
If we are talking of a translator specific situation, then the translator should do the encoding forward and backwards. It should receive enough context to identify such a situation.
Altering the item that is captured makes the data in TMGMT dependent on a specific not yet fixed translator...
(If you need custom variant of a translator to add special handling, you can subclass its implementation.)
I would be happy to understand this requirements and have a good example before adding the complexity in 8.x-1.x.
Comment #18
berdirYeah, I don't really believe that's a good use either, although if you just use a single translator then you can do whatever you want, i don't really care.
Better use cases would be to implement custom support for field types that we don't support property yet or adding special cases for some fields/field types.
Comment #24
miro_dietikerHmm wrote quite a bit about this and then decided to drop. Retrying. ;-)
Yeah a source might be incomplete and should possibly offer adding more values.
What we tried with suggestions is currently too limited. I originally also wanted to add flags to suggestions that lead to force add or priorisation in UI.
A similar thing is what we do with resolving references now that add more data.
For these kind of extensions, it's just important that they don't overlap with internal workflows and are really only triggered on source capture and on write back for pre / post processing... so that TMGMT could introduce a translation memory that is not tainted with altered values and that can still be kept in sync with everything.