Expose the `meta` field in the form scope
authorTim Otten <totten@civicrm.org>
Wed, 13 Jun 2018 06:40:26 +0000 (23:40 -0700)
committerCiviCRM <info@civicrm.org>
Wed, 16 Sep 2020 02:13:16 +0000 (19:13 -0700)
ext/afform/afform.php
ext/afform/ang/afformCore.js
ext/afform/templates/afform/FormAsDirective.tpl

index 2ec594afa971e2db4fe8bb66024447dd7cbd3707..a0566f066df664670eace06b5ea2f6498207bf6b 100644 (file)
@@ -186,13 +186,15 @@ function afform_civicrm_buildAsset($asset, $params, &$mimeType, &$content) {
   }
 
   $name = $params['name'];
-  $meta = civicrm_api3('Afform', 'getsingle', ['name' => $name]);
+  $scanner = new CRM_Afform_AfformScanner();
+  $meta = $scanner->getMeta($name);
   $scanner = new CRM_Afform_AfformScanner();
 
   $smarty = CRM_Core_Smarty::singleton();
   $smarty->assign('afform', [
     'camel' => _afform_angular_module_name($name),
     'meta' => $meta,
+    'metaJson' => json_encode($meta),
     'layout' => file_get_contents($scanner->findFilePath($name, 'layout.html'))
   ]);
   $mimeType = 'text/javascript';
index 2488968454aa53df9070aae9fd7211a241e80157..7548db1f5c8c68474db07810ef9f281efc4becf9 100644 (file)
@@ -6,13 +6,14 @@
 
   // Use `afformCoreDirective(string name)` to generate an AngularJS directive.
   angular.module('afformCore').service('afformCoreDirective', function($routeParams){
-    return function(camelName, d){
+    return function(camelName, meta, d){
       d.restrict = 'AE';
       d.scope = {};
       d.scope.options = '=' + camelName;
       d.link = function($scope, $el, $attr) {
         $scope.ts = CRM.ts(camelName);
         $scope.routeParams = $routeParams;
+        $scope.meta = meta;
       };
       return d;
     };
index f448ad4406aed925a5becc64960426a315ccaa17..ec8511c82a53236c50c94439667ffee79d2a2168 100644 (file)
@@ -8,7 +8,7 @@
 (function(angular, $, _) {
   angular.module('{/literal}{$afform.camel}{literal}', CRM.angRequires('{/literal}{$afform.camel}{literal}'));
   angular.module('{/literal}{$afform.camel}{literal}').directive('{/literal}{$afform.camel}{literal}', function(afformCoreDirective) {
-    return afformCoreDirective({/literal}{$afform.camel|json}{literal}, {
+    return afformCoreDirective({/literal}{$afform.camel|json},{$afform.metaJson}{literal}, {
       template: {/literal}{$afform.layout|json}{literal}
     });
   });