-
-
Notifications
You must be signed in to change notification settings - Fork 825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dev/core#463 Add in ability for Extensions to use their Extension Utils class to s… #12986
Conversation
(Standard links)
|
Note that there is a corresponding PR for civix here it totten/civix#143 |
In terms of use-case, makes sense to me! |
xml/templates/dao.tpl
Outdated
@@ -8,6 +8,11 @@ | |||
* (GenCodeChecksum:{$genCodeChecksum}) | |||
*/ | |||
|
|||
|
|||
{if $extension} | |||
extesniontuils |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo?
f06d55b
to
136e5e3
Compare
I've added merge-ready. Ideally @totten will comment & we should hold a bit for that - but not that long as we know Tim can't look at everything & this is fairly minor |
xml/templates/dao.tpl
Outdated
|
||
{if $extension} | ||
extensionutils | ||
{/if} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mlutfy it outputs a string that then CiviX swaps out for a use CRM_<extesnionname>_Utils as E;
here https://github.com/totten/civix/pull/143/files#diff-b961fdd9b92320d1fd7efa5fd0f49cfeR92 I was struggling to get gencode to respect the spaces between use and the CRM... so did it this way around
xml/templates/dao.tpl
Outdated
@@ -90,7 +95,7 @@ class {$table.className} extends CRM_Core_DAO {ldelim} | |||
'name' => '{$field.name}', | |||
'type' => {$field.crmType}, | |||
{if $field.title} | |||
'title' => ts('{$field.title}'), | |||
'title' => {if $extension}E::ts{else}ts{/if}('{$field.title}'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On a functional level, 👍 for having any DAO's in the extension use the extension's translation domain.
FWIW, when writing the template for the extension utils class, I explicitly wanted to avoid making CRM_Foobar_ExtensionUtil
classes into a public contract (or inter-module contract). For example, it does not extend any shared base class
or shared interface
. The original/intended audience was only the author of the civix-generated module -- it was not designed to be shared/public-contract.
Why?
(1) There are already public contracts for things like ts(...'domain' => ...)
-- using the E
class an inter-module contract would be duplicative and (2) civix is only supposed to be a template/skeleton generator. If an author wants to totally muck with all the code in there, then that should still be workable. But if others depend on civix-isms, then the dependency graph can get weird.
This patch is interesting because it lets the downstream inject the statement like use CRM_Foobar_ExtensionUtil as E
-- technically, the core code doesn't know anything about CRM_Foobar_ExtensionUtil
, but it does know about this virtual symbol E
and E::ts()
.
Would this patch mean that core code has some dependency on a civix convention? Honestly, it's right on the line. I think it's technically, currently on the safe side of the line. My hesitation is more with the precedent -- if other things in core start to depend on having an E
class, then E
will become a public contract leading eventually to funny loops.
Just to put it out there, here are a couple alternatives:
- (a) Have the civix generator pass the extension-key
org.example.foobar
or translation-domain for use indao.tpl
. Indao.tpl
, it conditionally passes this forts(... ['domain' => ...])
. - (b) Have the civix generator pass an expression for the translation callback (e.g.
$ts = 'CRM_Foobar_Extension::ts'
). Indao.tpl
, it uses this instead of a straight call tots()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@totten yeh i see your point but also I think this also about ensuring we have a separation between Core (ts) and the Extensions routing through their E utils class
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, so a routing point is useful because it gives you some leverage -- you make a change in one spot, and it applies to several use-cases.
E::ts()
doesn't give us that:
- Within an extension,
E::ts()
is used by newer PHP code, but it's not used by Smarty code, Javascript code, or older PHP code. To makeE::ts()
useful as a router, one would have to rework all those other call-paths. - If you do make a change in
E::ts()
, it's liable to get trounced later on -- because it's part of the autogenerated*.civix.php
boilerplate.
The common-denominator is that all paths lead to the global ts()
function (with a domain
argument). If one wants the benefit of routing (i.e. a leverage point where you can structurally manipulate all translations of a given extension/domain/purpose), then you currently have to look at the global ts()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@totten so then would you suggest that its better to perhaps add an extra function called like ts to extension DAOs that then calls the global ts function with the domain param?
136e5e3
to
68b687f
Compare
@totten i believe this is now updated as per our discussion just now |
@totten @eileenmcnaughton i have confirmed that this produces the same output for Core as previous and confirmed that it works for extensions. This also does not bind Core to Extension purposes as previous and resolves Tim's concerns |
@seamuslee001 looks good to me |
Jenkins re test this please |
…ls class to supply ts Functions in DAOs Update DAO generation using ts function name as per conversation with Tim
68b687f
to
8af97d9
Compare
test this please |
Jenkins reset this please |
merging as per the tag |
…upply ts Functions in DAOs
Overview
This allows for Civix or similar to ensure that when the DAO is generated that it uses instead of ts E::ts and that civix can insert the relevant use statement to use the Extensions' utils class
Before
No extension utils in DAO
After
Extension utils exists
Technical details
When creating a new entity (e.g DiscountItem) via an extension the new entity will need a DAO class. Our Civix code currently supports this - at least somewhat - but will not wrap any translatables with
ts
rather than the (correct for extensions)E::ts
. Adding this to core will allow civix to leverage it to better create extension DAO objects