I have two bundles for my entity, each are administer in a different way. (Code/functional wise they are similar, but front-end/use-wise the goal is different). So I put them in different place in the admin, with the result that I have two very different path structures for viewing and managing these bundles.
Entity core more or less support this allowing us to define different uri callbacks per bundle and defining different administration pages. It would be nice if entity translation would also support something similar.
It might be as easy as allowing the base path parameter to be an array. Or allowing developers to define a bundle array within the entity_translation array where you can override individual options per bundle.
Comments
Comment #1
plachThe per-bundle path approach looks reasonable to me. Patches welcome.
Comment #2
plachThis will probably needed to fix #1470018: Provide Entity Translation integration. Therefore we will need just multiple arrays, per-bundle base paths wouldn't work in that case.
Comment #3
plachI think we should allow the
'base path'
key to be an array, but keep the possibility to have a single string value for BC. The base path is also used as default to construct the edit and view paths (which are used to generate UI links), which instead need to be unique. I'd just choose the first available base path in that case.Comment #4
bforchhammer CreditAttribution: bforchhammer commentedComment #5
bforchhammer CreditAttribution: bforchhammer commentedAttached is a first stab at allowing the 'base path' to be an array while leaving edit and view paths unique. Not sure how to test this or apply it for #1470018: Provide Entity Translation integration though...
Don't we need multiple edit paths for a localized form on
media/%file/edit/%nojs
(i.e. in the "edit media" popup)?Comment #6
plach@bforchhammer
Thanks for the patch!
Yes, exactly. We need to support both the regular
file/%file
and themedia/%file/edit/%nojs
popup path.Comment #7
plachFrom a cursory look the code looks code: I'd say it needs manual testing, however setting to NR to see if the bots complains.
Comment #8
bforchhammer CreditAttribution: bforchhammer commentedSo, just to clarify: we DO need to allow/support arrays for edit path (and view path?) as well? Patch above only allows the base path to be an array... ;)
If yes, should the translation handlers also know about all paths, or just the "first one"? What aspects need to remain unique?
Comment #9
bforchhammer CreditAttribution: bforchhammer commentedHere's a new patch which allows arrays for 'base path', 'edit path', 'view path' and 'path wildcard'. Our implementation of
hook_entity_info_alter()
makes sure they are always stored as array values in the entity info array.Now, if I add the additional media edit path the form automatically shows up translated when I click "edit media" :) Everything else also still seems to be working...
API docs still need fixing, and I left in code which adds the additional media edit path.
Comment #10
bforchhammer CreditAttribution: bforchhammer commentedSo, the question remains: does it make sense to make the 'view path' key an array? I guess it's possible that there are multiple view paths, but I don't think entity translation needs to know about it?
Using a closure adds a dependency on PHP version >=5.3. Is that okay?
Obviously needs to go somewhere else... where?
Currently only throws an error if the first base path is invalid. Do additional base paths need to validated as well?
Comment #11
bforchhammer CreditAttribution: bforchhammer commentedHere's a reroll of #9, as it didn't apply cleanly anymore...
Comment #12
bforchhammer CreditAttribution: bforchhammer commentedHere's a new patch which fixes the issues mentioned in #10. I decided for making 'view path' an array for consistency, removed the php closure (D7 officially supports PHP <5.3), removed the media-specific code, added validation for all base paths, and added some basic documentation to the api file.
Comment #13
bforchhammer CreditAttribution: bforchhammer commentedAn aspect which I'm not quite happy with, is that this approach does not consider dependencies between the different path related elements; e.g. all path wildcards are stored in one array, even though they should only be used for the respective menu path. Theoretically this could lead to the wrong path wildcard being used to identify an entity... Similarly,
$base_path/edit
is currently always added as an edit path; in most cases this will be fine, but if some entity wants to use that path for something else then there's currently no way to prevent ET from overriding it.Maybe it would be better to allow the definition of multiple "path sets", like e.g. the following:
Of course we'd have to make sure that the current (simpler) way for defining paths is still supported as well (in hook_entity_info_alter).
Other issues:
$base_path/translate
, to allow modification of the translate path?Comment #14
plachThe plan in #13 sounds good to me.
Not sure about this: I think that enforcing a bit of consistency would be better and the translation handler can always be replaced with a specialized version overriding the
get*Path()
methods in extreme cases. OTOH having agetTranslatePath()
method would make sense. No strong preference here.Anyway, I see another potential issue with the current approach: by defaulting to the first base path and friends we are basically ignoring context. For instance if we consider the original use case that spawned this issue (Media), we have two base paths:
file/%file
and
fancy/popup/whose/path/I/don-t/remember/exactly/%fancy_popup_file
When displaying the translation overview page at
fancy/popup/whose/path/I/dont/remember/exactly/%fancy_popup_file/translate
all links will point to
file/%file
andfile/%file/edit
. And if we want to skip the translate tab, which probably would not appear, and just provide the language switcher tabs we would incur in the same problem, I guess. This make me think we probably need to default to the current router path if it matches one of the base paths. We should set the default base path through a method, default to the current router path if none is provided and fall back to the first one if it does not match any defined base path.Missing space after "if".
Comment #15
bforchhammer CreditAttribution: bforchhammer commentedAttached is a new patch which...
Let's see whether I've broken anything. Go testbot.
Comment #17
bforchhammer CreditAttribution: bforchhammer commentedAnd again...
Comment #18
plachAwesome! I made some code clean-up and removed special-casing for the node admin theme.
I think we still need to set the active patch scheme based on the current router path.
Comment #19
plachSetting NR for the bot but it's still NW.
Comment #20
plachComment #21
bforchhammer CreditAttribution: bforchhammer commentedAttached patch adds code to find the active path scheme based on the value of
$_GET[q]
.Not sure whether this is the best approach; we should probably try to reuse more core-menu functionality, however using e.g.
menu_get_item()
to get the active router does not work as it leads to an infinite loop... (When I tested it, the translation handler was constructed duringentity_translation_field_language_alter()
, which itself is invoked via theentity_load()
call duringmenu_get_item()
).Comment #22
plachNice! The attached patch slightly changes the initialization of the path scheme based on the router path: I think it's better to explictly initialize path schemes. The router map obtained this way let us deal with multiple loaders/wildcards inside the same router path. This also avoids the recursion problems mentioned above.
I actually tested the patch with Media (#1418644-7: Add multilingual support for files and #1470018-8: Provide Entity Translation integration) and it seems to work fine. I think it's ready to go in, if you are ok with it.
Comment #23
bforchhammer CreditAttribution: bforchhammer commentedYeah, that's looking good :)
I'll commit #22 with some minor changes in a minute...
Comment #24
plachGo!
Comment #25
bforchhammer CreditAttribution: bforchhammer commentedCommitted and pushed the attached patch :)
Comment #26
plachWhoo-hoo, beta1 approaching!
Let's if we can get some feedback in the File entity/Media issues. Review/testing of patches would be welcome: let's get them RTBC!
Comment #27
plachRelated issue: #1676716-6: Do not list entity types that do not integrate with ET in the admin page.
Comment #28
PanchoNote that at least on existing installs, this patch causes a notice, a warning and an exception:
Reversing the patch helped on both installs.
Reopening this as a critical bug to allow for a quick followup. To be demoted to a normal task before closing.
Comment #29
plachJust clear the caches.