Closed (fixed)
Project:
Entity Translation
Version:
7.x-1.x-dev
Component:
Base system
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
30 Mar 2011 at 17:46 UTC
Updated:
5 Mar 2013 at 09:46 UTC
I would like to try to implement the translation of profile2 (http://drupal.org/project/profile2) entities.
I explored the code a bit but would like to know if some of the maitainers could point me to a good starting point (doc, sample code, tutorial, whatever).
Any information would be useful.
Comments
Comment #1
Countzero commentedAs of now, I'm just trying to make the profile2 type appear on admin/config/regional/entity_translation.
I implemented this :
... in profile2.module (translation_profile2_tab_access returns TRUE) and this :
... which I know won't be functional but just I'm just starting.
Nothing happened on the page yet, so if anybody can point me to what I'm missing ...
Comment #2
Countzero commentedWell, in fact it was already there and I feel really stupid.
So I guess it's a matter of providing the correct info to ET to give the correct paths to edit the translations.
Anyway, any info about this is also welcome.
Comment #3
plachYes,
hook_translation_info(which I am planning to deprecate in favor of a plainhook_entity_infoimplementation, btw) can be used to override information for the UI paths, translation handler classes and so on. The defaults should work in most cases, the most important info is perhaps thebase pathwhich actually enables the translate tab.Just keep in mind that the implementation in #1 is wrong, the correct array structure is:
Comment #4
Countzero commentedThanks a lot for this answer.
The paths are managed in a very special way in profile2 and I guess that's why I have such a hard time implementing at least a basic working thing.
In profile2, the actual entity is never accessible directly, but through the user pages, so finding the right menu path is not easy.
Am I right thinking the end path should be /profile2/pid/translate, just like nodes ?
Also, I'm not sure if all the node code should be implemented or if things are supposed to work as is.
Comment #5
plachWe already have an open issue for the problem of attaching the translate tab to complex base paths: #1092332: Support arbitrary base paths, perhaps it is the moment to address this issue in a more solid way.
Comment #6
Countzero commentedOK, my ego feels better ;-).
I'll have a look at this issue after I have finished to implement my ugly temporary hack for my use case.
Comment #7
Countzero commentedDid some tests : as soon as I define a base path (even with only one wildcard) in profile2_translation_info, I cannot access profile information in user/xxx/edit/main anymore : the form displays empty values.
Comment #8
Countzero commentedAs of now, providing any base path leads to problems, even without any wildcard.
Comment #9
Countzero commentedAnother note : the access callback seems mandotary, otherwise it throws a notice saying
Notice : Undefined index: access callback in entity_translation_menu() (ligne 171
Comment #10
plachSee if it is the same error we get in #936646: Undefined index access callback/arguments in translation_menu.
Comment #11
Countzero commentedI don't think so. The faulty line is this one :
It's simply a direct reference to an inexisting index so nothing to write home about. I don't define the access callback, ET tells me so, period.
I went a bit further : I set a fake path like this :
'base path' => 'user/7/edit/main/7'and tried to access user/7/edit/main/7/translate.
This error came out :
Fatal error: Call to a member function label() on a non-object in /srv/sites/web59/web/sites/all/modules/entity/entity.module on line 724
Trying to follow the track up to the faulty call.
Comment #12
Countzero commentedBacktracing, I came to
... in entity_translation.admin.inc where $translations seems to be empty even after the 'if' statement.
Comment #13
plachPlease, don't post every step. Create an issue when you find a standalone bug or post a summary when you come up with a sensible result, after all this is a feature request not a collector of sparse bug reports.
Comment #14
Countzero commentedI thought giving as much feedback as possible could be useful. But well ...
Comment #15
plachThe problem here is we are going OT.
If you have problems with attaching the translate tab to a base path, you should file a separate bug report summarizing the issue (unless we want to turn this one into a bug report). Then if you mean to fix the bug just post your solution along with a description. A series of debugging steps does not help too much, and distract me (I get an email notification for each post :)
Comment #16
Countzero commentedI turn this into a bug report, as I don't need the feature so much now.
I was trying to help on good intent. I thought the steps could be useful for you to debug your module. I understand they're not so I won't do it again.
Comment #17
plachNo bad feelings I hope: any help is welcome if well focused :)
Comment #18
Countzero commentedNo bad feelings : just a little overreaction after a hard day of work.
See you.
Comment #19
Countzero commentedBack to business, but not with very much success.
One thing (among many others) I don't understand, and I hope you'll agree to help me about :
This code :
... passes two arguments from the URL to the entity_translation_overview function.
This function then treats the second argument, and actually succeeds, as an entity object.
I cannot understand how a numeric argument can become a class instance between the menu entry and the actual function code. Is there some Drupal magic I'm not aware of going on here ?
It works for node entities but all my tries with profile entities lead up to errors because the numeric argument stays so and never becomes a class which the entity_translation_overview can handle.
Maybe I just need some rest ...
Comment #20
plachIt is the standard way to define menu items: the
'page arguments'array specifies in which position of the menu path the entity object can be found. For instance in'node/%node/translate'you find the entity object (actually the menu loader wildcard) in the second position (index 1),$entity_positionbasically just holds the computed value assuming that there will be at some point a menu loader wildcard which the/translatesegment needs to be appeded to:'node/%node/translate''taxonomy/term/%term/translate'etc.
Obviously this scheme is not flexible enough to cover each use case.
Comment #21
Countzero commentedThanks for your answer. I thought I had understood this system, but obviously I don't.
So the value holded by the wildcard must be passed to a loader function isn't it ? Because the URL just holds an id, not an object. I saw there is a function called entity_translation_menu_entity_load but it doesn't seem to get called at any time.
Comment #22
plachWell, autoloaders appearing in the base paths are supposed to be provided by the entity modules theirselves, for instance
%nodemaps tonode_load(), this wayentity_translation_overview()gets a node instead of a nid.Comment #23
Countzero commentedOkay, now that I have a better understanding of the process, I managed to provide an arbitrary path and got the translation form loaded with a profile2 entity. The loader indeed exists in profile2 code. The menu callback has to be implemented like that :
Of course, it doesn't fit with profile2 architecture and only fulfills testing purposes but I think it can be useful to some.
With a usable base path, all the ET stuff works like a charm : you can add translatable fields, add translations to them and see the translated version appear on the other languages pages.
So the problem problem boils down, as you said before, to providing a real path, consistent with profile2 paths, which is not possible at the time being due to the aforementioned issue : #1092332: Support arbitrary base paths.
I think the ET part of the present issue is, if not solved, reduced to its root elements, so maybe you can close this but it's of course up to you.
Thanks for your patience.
Comment #24
plachJust a minor remark, the following definition should be more or less equivalent:
Comment #25
Countzero commentedMy, you're right. I was really off big time on this one. Will try to do better next time.
Comment #27
kurageart commentedHi... do you have any suggestion on how to make this work on core drupal profiles (with attached fields)? thanks