Skip to content

Commit

Permalink
dev/core#463 Add in ability for Extensions to use their Extension Uti…
Browse files Browse the repository at this point in the history
…ls class to supply ts Functions in DAOs

Update DAO generation using ts function name as per conversation with Tim
  • Loading branch information
seamuslee001 committed Oct 30, 2018
1 parent 40b45f2 commit 8af97d9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
12 changes: 11 additions & 1 deletion CRM/Core/CodeGen/DAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,23 @@ class CRM_Core_CodeGen_DAO extends CRM_Core_CodeGen_BaseTask {
*/
private $raw;

/**
* @var string
* translate function name
*/
private $tsFunctionName;

/**
* CRM_Core_CodeGen_DAO constructor.
*
* @param \CRM_Core_CodeGen_Main $config
* @param string $name
* @param string $tsFunctionName
*/
public function __construct($config, $name) {
public function __construct($config, $name, $tsFunctionName = 'ts') {
parent::__construct($config);
$this->name = $name;
$this->tsFunctionName = $tsFunctionName;
}

/**
Expand Down Expand Up @@ -69,6 +77,7 @@ public function run() {
$template->assign('indicesPhp', var_export($this->tables[$this->name]['index'], 1));
}
$template->assign('genCodeChecksum', $this->getTableChecksum());
$template->assign('tsFunctionName', $this->tsFunctionName);
$template->run('dao.tpl', $this->getAbsFileName());
}

Expand All @@ -88,6 +97,7 @@ public function getRaw() {
$template->assign('indicesPhp', var_export($this->tables[$this->name]['index'], 1));
}
$template->assign('genCodeChecksum', 'NEW');
$template->assign('tsFunctionName', $this->tsFunctionName);
$this->raw = $template->fetch('dao.tpl');
}
return $this->raw;
Expand Down
6 changes: 3 additions & 3 deletions xml/templates/dao.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ class {$table.className} extends CRM_Core_DAO {ldelim}
'name' => '{$field.name}',
'type' => {$field.crmType},
{if $field.title}
'title' => ts('{$field.title}'),
'title' => {$tsFunctionName}('{$field.title}'),
{/if}
{if $field.comment}
'description' => ts('{$field.comment|replace:"'":"\'"}'),
'description' => {$tsFunctionName}('{$field.comment|replace:"'":"\'"}'),
{/if}
{if $field.required}
'required' => {$field.required|strtoupper},
Expand Down Expand Up @@ -148,7 +148,7 @@ class {$table.className} extends CRM_Core_DAO {ldelim}
{if $field.html}
'html' => array(
{foreach from=$field.html item=val key=key}
'{$key}' => {if $key eq 'label'}ts("{$val}"){else}'{$val}'{/if},
'{$key}' => {if $key eq 'label'}{$tsFunctionName}("{$val}"){else}'{$val}'{/if},
{/foreach}
),
{/if}
Expand Down

0 comments on commit 8af97d9

Please sign in to comment.