Afform - Fix loading entities from url args
authorColeman Watts <coleman@civicrm.org>
Mon, 26 Apr 2021 04:22:52 +0000 (00:22 -0400)
committerColeman Watts <coleman@civicrm.org>
Mon, 26 Apr 2021 04:34:00 +0000 (00:34 -0400)
This broke when we stopped using ngRoute.
Now entities can be loaded with a url like civicrm/my/afform#!?Individual1=123

ext/afform/core/ang/af/afForm.component.js
ext/afform/core/ang/afCore.ang.php

index 2c36a9ec077aa9c9f2c8b4eef5ff81b041fa94f8..b39a297ad2c5a6b6d551aef33e49568a8e416215 100644 (file)
@@ -4,7 +4,7 @@
     bindings: {
       ctrl: '@'
     },
-    controller: function($scope, $routeParams, $timeout, crmApi4, crmStatus, $window, $location) {
+    controller: function($scope, $timeout, crmApi4, crmStatus, $window, $location) {
       var schema = {},
         data = {},
         ctrl = this;
         return $scope.$parent.meta;
       };
       this.loadData = function() {
-        var toLoad = 0;
+        var toLoad = 0,
+          args = $scope.$parent.routeParams || {};
         _.each(schema, function(entity, entityName) {
-          if ($routeParams[entityName] || entity.autofill) {
+          if (args[entityName] || entity.autofill) {
             toLoad++;
           }
         });
         if (toLoad) {
-          crmApi4('Afform', 'prefill', {name: ctrl.getFormMeta().name, args: $routeParams})
+          crmApi4('Afform', 'prefill', {name: ctrl.getFormMeta().name, args: args})
             .then(function(result) {
               _.each(result, function(item) {
                 data[item.name] = data[item.name] || {};
@@ -53,7 +54,7 @@
       };
 
       this.submit = function submit() {
-        var submission = crmApi4('Afform', 'submit', {name: ctrl.getFormMeta().name, args: $routeParams, values: data});
+        var submission = crmApi4('Afform', 'submit', {name: ctrl.getFormMeta().name, args: $scope.$parent.routeParams || {}, values: data});
         var metaData = ctrl.getFormMeta();
         if (metaData.redirect) {
           submission.then(function() {
index 1251fe829517aad6faf0109b1c14c57c72fcf683..9b23b737b200131e1596a40e4964b4672f45824c 100644 (file)
@@ -7,7 +7,7 @@ return [
     'ang/afCore/*/*.js',
   ],
   'css' => ['ang/afCore.css'],
-  'requires' => ['crmUi', 'crmUtil', 'api4', 'checklist-model', 'ngRoute'],
+  'requires' => ['crmUi', 'crmUtil', 'api4', 'checklist-model'],
   'partials' => ['ang/afCore'],
   'settings' => [],
   'basePages' => [],