From: Coleman Watts Date: Sun, 7 Aug 2022 01:32:14 +0000 (-0400) Subject: Afform - Fix compatability of existing contact widget and 'current user' default X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=12308f3113c5e45c00eeb9dcfe709b8ea6b24260;p=civicrm-core.git Afform - Fix compatability of existing contact widget and 'current user' default --- diff --git a/ext/afform/core/Civi/Api4/Action/Afform/AbstractProcessor.php b/ext/afform/core/Civi/Api4/Action/Afform/AbstractProcessor.php index 17c25b78f3..fb58a574da 100644 --- a/ext/afform/core/Civi/Api4/Action/Afform/AbstractProcessor.php +++ b/ext/afform/core/Civi/Api4/Action/Afform/AbstractProcessor.php @@ -9,6 +9,9 @@ use Civi\Api4\Utils\CoreUtil; /** * Shared functionality for form submission pre & post processing. * @package Civi\Api4\Action\Afform + * + * @method $this setFillMode(string $fillMode) Set entity/form fill mode. + * @method string getFillMode() */ abstract class AbstractProcessor extends \Civi\Api4\Generic\AbstractAction { @@ -25,6 +28,13 @@ abstract class AbstractProcessor extends \Civi\Api4\Generic\AbstractAction { */ protected $args = []; + /** + * Used by prefill action to indicate if the entire form or just one entity is being filled. + * @var string + * @options form,entity + */ + protected $fillMode = 'form'; + /** * @var array */ @@ -79,7 +89,7 @@ abstract class AbstractProcessor extends \Civi\Api4\Generic\AbstractAction { $ids = array_slice($ids, 0, !empty($entity['af-repeat']) ? $entity['max'] ?? NULL : 1); $this->loadEntity($entity, $ids); } - elseif (!empty($entity['autofill'])) { + elseif (!empty($entity['autofill']) && $this->fillMode !== 'entity') { $this->autofillEntity($entity, $entity['autofill']); } } diff --git a/ext/afform/core/ang/af/afField.component.js b/ext/afform/core/ang/af/afField.component.js index 1e0cda0dbc..63d0021f24 100644 --- a/ext/afform/core/ang/af/afField.component.js +++ b/ext/afform/core/ang/af/afField.component.js @@ -169,6 +169,7 @@ } }; + // ngChange callback from Existing entity field ctrl.onSelectExisting = function() { var val = $scope.getSetSelect(); var entity = ctrl.afFieldset.modelName; diff --git a/ext/afform/core/ang/af/afForm.component.js b/ext/afform/core/ang/af/afForm.component.js index 314d710cc5..dbaa9c9104 100644 --- a/ext/afform/core/ang/af/afForm.component.js +++ b/ext/afform/core/ang/af/afForm.component.js @@ -45,9 +45,12 @@ // Load single entity if (selectedEntity) { toLoad = selectedId; + params.fillMode = 'entity'; params.args[selectedEntity] = {}; params.args[selectedEntity][selectedIndex] = selectedId; - } else { + } + // Prefill entire form + else { args = _.assign({}, $scope.$parent.routeParams || {}, $scope.$parent.options || {}); _.each(schema, function (entity, entityName) { if (args[entityName] || entity.autofill) { @@ -68,6 +71,13 @@ }); }); } + // Clear existing contact selection + else if (selectedEntity) { + data[selectedEntity][selectedIndex].fields = {}; + if (data[selectedEntity][selectedIndex].joins) { + data[selectedEntity][selectedIndex].joins = {}; + } + } }; // Used when submitting file fields