/**
* 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 {
*/
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
*/
$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']);
}
}
}
};
+ // ngChange callback from Existing entity field
ctrl.onSelectExisting = function() {
var val = $scope.getSetSelect();
var entity = ctrl.afFieldset.modelName;
// 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) {
});
});
}
+ // 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