Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
CiviCRM Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Development
CiviCRM Core
Commits
95102016
Commit
95102016
authored
5 months ago
by
colemanw
Browse files
Options
Downloads
Patches
Plain Diff
Afform - Do not set LocBlock id if exposed to the form
parent
66c05284
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
ext/afform/core/Civi/Api4/Action/Afform/Submit.php
+2
-2
2 additions, 2 deletions
ext/afform/core/Civi/Api4/Action/Afform/Submit.php
ext/afform/mock/tests/phpunit/api/v4/Afform/AfformEventUsageTest.php
+108
-1
108 additions, 1 deletion
...mock/tests/phpunit/api/v4/Afform/AfformEventUsageTest.php
with
110 additions
and
3 deletions
ext/afform/core/Civi/Api4/Action/Afform/Submit.php
+
2
−
2
View file @
95102016
...
...
@@ -460,8 +460,8 @@ class Submit extends AbstractProcessor {
// Forward FK e.g. Event.loc_block_id => LocBlock
$forwardFkField
=
self
::
getFkField
(
$mainEntity
[
'type'
],
$joinEntityName
);
if
(
$forwardFkField
&&
$values
)
{
// Add id to values for update op
if
(
$whereClause
)
{
// Add id to values for update op
, but only if id is not already on the form
if
(
$whereClause
&&
empty
(
$mainEntity
[
'joins'
][
$joinEntityName
][
'fields'
][
$joinIdField
])
)
{
$values
[
0
][
$joinIdField
]
=
$whereClause
[
0
][
2
];
}
$result
=
civicrm_api4
(
$joinEntityName
,
'save'
,
[
...
...
This diff is collapsed.
Click to expand it.
ext/afform/mock/tests/phpunit/api/v4/Afform/AfformEventUsageTest.php
+
108
−
1
View file @
95102016
...
...
@@ -2,13 +2,14 @@
namespace
api\v4\Afform
;
use
Civi\Api4\Afform
;
use
Civi\Test\TransactionalInterface
;
/**
* Test case for Afform.prefill and Afform.submit with Event records.
*
* @group headless
*/
class
AfformEventUsageTest
extends
AfformUsageTestCase
{
class
AfformEventUsageTest
extends
AfformUsageTestCase
implements
TransactionalInterface
{
use
\Civi\Test\Api4TestTrait
;
/**
...
...
@@ -75,4 +76,110 @@ EOHTML;
$this
->
assertSame
(
'2234567'
,
$prefill
[
'values'
][
0
][
'joins'
][
'LocBlock'
][
0
][
'phone_id.phone'
]);
}
/**
* Test saving & updating
*/
public
function
testEventLocationUpdate
():
void
{
$layout
=
<<<EOHTML
<af-form ctrl="afform">
<af-entity actions="{create: true, update: true}" type="Event" name="Event1" label="Event 1" security="FBAC" />
<fieldset af-fieldset="Event1" class="af-container" af-title="Event 1">
<af-field name="id" />
<af-field name="title" />
<af-field name="start_date" />
<af-field name="event_type_id" />
<div af-join="LocBlock">
<af-field name="id" />
<af-field name="email_id.email" />
<af-field name="address_id.street_address" />
</div>
</fieldset>
<button class="af-button btn btn-primary" crm-icon="fa-check" ng-click="afform.submit()">Submit</button>
</af-form>
EOHTML;
$this
->
useValues
([
'layout'
=>
$layout
,
'permission'
=>
\CRM_Core_Permission
::
ALWAYS_ALLOW_PERMISSION
,
]);
// Create a new event with a new location
$submit
=
Afform
::
submit
()
->
setName
(
$this
->
formName
)
->
setValues
([
'Event1'
=>
[
[
'fields'
=>
[
'title'
=>
'Event Title 1'
,
'start_date'
=>
'2021-01-01 00:00:00'
,
'event_type_id'
=>
1
,
],
'joins'
=>
[
'LocBlock'
=>
[
[
'email_id.email'
=>
'test1@te.st'
,
'address_id.street_address'
=>
'12345'
,
],
],
],
],
],
])
->
execute
();
$event1
=
$submit
[
0
][
'Event1'
][
0
][
'id'
];
$loc1
=
$submit
[
0
][
'Event1'
][
0
][
'joins'
][
'LocBlock'
][
0
][
'id'
];
// Create a 2nd new event with a new location
$submit
=
Afform
::
submit
()
->
setName
(
$this
->
formName
)
->
setValues
([
'Event1'
=>
[
[
'fields'
=>
[
'title'
=>
'Event Title 2'
,
'start_date'
=>
'2022-01-01 00:00:00'
,
'event_type_id'
=>
1
,
],
'joins'
=>
[
'LocBlock'
=>
[
[
'id'
=>
$loc1
,
],
],
],
],
],
])
->
execute
();
$event2
=
$submit
[
0
][
'Event1'
][
0
][
'id'
];
$this
->
assertGreaterThan
(
$event1
,
$event2
);
$this
->
assertSame
(
$loc1
,
$submit
[
0
][
'Event1'
][
0
][
'joins'
][
'LocBlock'
][
0
][
'id'
]);
// Update event 1 with a new location
$submit
=
Afform
::
submit
()
->
setName
(
$this
->
formName
)
->
setValues
([
'Event1'
=>
[
[
'fields'
=>
[
'id'
=>
$event1
,
'title'
=>
'Event Title 1 Updated'
,
],
'joins'
=>
[
'LocBlock'
=>
[
[
'id'
=>
NULL
,
'address_id.street_address'
=>
'12345'
,
],
],
],
],
],
])
->
execute
();
$this
->
assertSame
(
$event1
,
$submit
[
0
][
'Event1'
][
0
][
'id'
]);
$this
->
assertGreaterThan
(
$loc1
,
$submit
[
0
][
'Event1'
][
0
][
'joins'
][
'LocBlock'
][
0
][
'id'
]);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment