From 27a7e64158153341bd0d42d6314af538dc46924c Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Tue, 10 Dec 2019 22:01:16 -0500 Subject: [PATCH] Use dynamic snippet for afform module layout. --- ext/afform/core/afform.php | 11 +++++------ .../core/templates/afform/AfformAngularModule.tpl | 4 ++-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/ext/afform/core/afform.php b/ext/afform/core/afform.php index 273ed37c83..62759fe6b4 100644 --- a/ext/afform/core/afform.php +++ b/ext/afform/core/afform.php @@ -165,20 +165,19 @@ function afform_civicrm_angularModules(&$angularModules) { $names = array_keys($scanner->findFilePaths()); foreach ($names as $name) { $meta = $scanner->getMeta($name); + $layout = $scanner->getLayout($name); $angularModules[_afform_angular_module_name($name, 'camel')] = [ 'ext' => E::LONG_NAME, 'js' => ['assetBuilder://afform.js?name=' . urlencode($name)], 'requires' => $meta['requires'], 'basePages' => [], + 'snippets' => [ + "~afform/$name.aff.html" => $layout, + ], 'exports' => [ _afform_angular_module_name($name, 'dash') => 'AE', ], ]; - - // FIXME: The HTML layout template is embedded in the JS asset. - // This works at runtime for basic usage, but it bypasses - // the normal workflow for templates (e.g. translation). - // We should update core so that 'partials' can be specified more dynamically. } } @@ -413,7 +412,7 @@ function afform_civicrm_buildAsset($asset, $params, &$mimeType, &$content) { 'camel' => _afform_angular_module_name($name, 'camel'), 'meta' => $meta, 'metaJson' => json_encode($meta), - 'layout' => _afform_html_filter($name, $scanner->getLayout($name)), + 'templateUrl' => "~afform/$name.aff.html", ]); $mimeType = 'text/javascript'; $content = $smarty->fetch('afform/AfformAngularModule.tpl'); diff --git a/ext/afform/core/templates/afform/AfformAngularModule.tpl b/ext/afform/core/templates/afform/AfformAngularModule.tpl index 4a04137884..3af54b3178 100644 --- a/ext/afform/core/templates/afform/AfformAngularModule.tpl +++ b/ext/afform/core/templates/afform/AfformAngularModule.tpl @@ -10,8 +10,8 @@ angular.module('{/literal}{$afform.camel}{literal}', CRM.angRequires('{/literal}{$afform.camel}{literal}')); angular.module('{/literal}{$afform.camel}{literal}').directive('{/literal}{$afform.camel}{literal}', function(afCoreDirective) { return afCoreDirective({/literal}{$afform.camel|json},{$afform.metaJson}{literal}, { - template: {/literal}{$afform.layout|json}{literal} + templateUrl: {/literal}{$afform.templateUrl|json}{literal} }); }); })(angular, CRM.$, CRM._); -{/literal} \ No newline at end of file +{/literal} -- 2.25.1