Skip to content

Commit

Permalink
Form Builder - When cloning a form, assign it to a new path (PHP vari…
Browse files Browse the repository at this point in the history
…ant)

In this variant of the commit, we consolidate cloning logic on PHP side.
  • Loading branch information
totten committed Jan 21, 2025
1 parent b1e38c3 commit c0854e8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
20 changes: 20 additions & 0 deletions ext/afform/admin/Civi/Api4/Action/Afform/LoadAdminData.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ class LoadAdminData extends \Civi\Api4\Generic\AbstractAction {
*/
protected $skipEntities = [];

/**
* Set TRUE if creating a clone.
*
* Some properties (such as `name`, `title`, `server_route`) may be filtered.
*
* @var bool
*/
protected $clone = FALSE;

public function _run(\Civi\Api4\Generic\Result $result) {
$info = ['entities' => [], 'fields' => [], 'blocks' => []];
$entities = [];
Expand Down Expand Up @@ -220,6 +229,17 @@ public function _run(\Civi\Api4\Generic\Result $result) {
}
$info['blocks'] = array_values($info['blocks']);

if ($this->clone) {
unset($info['definition']['name']);
$info['definition']['title'] .= ' ' . ts('(copy)');
if (!empty($info['definition']['server_route'])) {
$info['definition']['server_route'] = $this->createDefaultRoute($info['definition']['type']);
}
if (!empty($info['definition']['navigation']['label'])) {
$info['definition']['navigation']['label'] .= ' ' . ts('(copy)');
}
}

$result[] = $info;
}

Expand Down
1 change: 1 addition & 0 deletions ext/afform/admin/ang/afAdmin.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
// Load data for gui editor
data: function($route, crmApi4) {
return crmApi4('Afform', 'loadAdminData', {
clone: true,
definition: {name: $route.current.params.name}
}, 0);
}
Expand Down
6 changes: 0 additions & 6 deletions ext/afform/admin/ang/afGuiEditor/afGuiEditor.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,6 @@
if (!editor.afform) {
alert('Error: unknown form');
}
if (editor.mode === 'clone') {
delete editor.afform.name;
delete editor.afform.server_route;
delete editor.afform.navigation;
editor.afform.title += ' ' + ts('(copy)');
}
editor.afform.icon = editor.afform.icon || 'fa-list-alt';
editor.afform.placement = editor.afform.placement || [];
$scope.canvasTab = 'layout';
Expand Down

0 comments on commit c0854e8

Please sign in to comment.