Skip to content

Commit

Permalink
Add in ability for Extensions to use their Extension Utils class to s…
Browse files Browse the repository at this point in the history
…upply ts Functions in DAOs
  • Loading branch information
seamuslee001 committed Oct 23, 2018
1 parent 4a030f0 commit f06d55b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
11 changes: 10 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;

/**
* @bool extension
* Are we generating a DAO for an Extension.
*/
private $extension;

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

/**
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('extension', $this->extension);
$template->run('dao.tpl', $this->getAbsFileName());
}

Expand Down
9 changes: 7 additions & 2 deletions xml/templates/dao.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
* (GenCodeChecksum:{$genCodeChecksum})
*/


{if $extension}
extesniontuils
{/if}

/**
* Database access object for the {$table.entity} entity.
*/
Expand Down Expand Up @@ -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}'),
{/if}
{if $field.comment}
'description' => '{$field.comment|replace:"'":"\'"}',
Expand Down Expand Up @@ -148,7 +153,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'}{if $extension}E::ts{else}ts{/if}("{$val}"){else}'{$val}'{/if},
{/foreach}
),
{/if}
Expand Down

0 comments on commit f06d55b

Please sign in to comment.