Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cmrf_form_processor
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
cmrf_form_processor
Commits
6fe04cec
Commit
6fe04cec
authored
1 year ago
by
jensschuppe
Committed by
Jaap Jansma
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3339639
: Add configuration option for when to execute the handler
parent
674afa9c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!2
Issue #3339639: Add configuration option for when to execute the handler
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Plugin/WebformHandler/FormProcessorWebformHandler.php
+71
-10
71 additions, 10 deletions
src/Plugin/WebformHandler/FormProcessorWebformHandler.php
with
71 additions
and
10 deletions
src/Plugin/WebformHandler/FormProcessorWebformHandler.php
+
71
−
10
View file @
6fe04cec
...
...
@@ -39,6 +39,11 @@ class FormProcessorWebformHandler extends WebformHandlerBase {
*/
protected
$tokenManager
;
/**
* The CiviMRF Core.
*
* @var \CMRF\Core\Core
*/
protected
$core
;
...
...
@@ -77,6 +82,7 @@ class FormProcessorWebformHandler extends WebformHandlerBase {
public
function
defaultConfiguration
()
{
return
[
'connection'
=>
null
,
'states'
=>
[
WebformSubmissionInterface
::
STATE_COMPLETED
],
'form_processor'
=>
null
,
'form_processor_fields'
=>
[],
'form_processor_params'
=>
[],
...
...
@@ -133,6 +139,25 @@ class FormProcessorWebformHandler extends WebformHandlerBase {
[
'#type'
=>
'fieldset'
,
'#title'
=>
$this
->
t
(
'Form Processor'
),
];
// Settings: States.
$results_disabled
=
$this
->
getWebform
()
->
getSetting
(
'results_disabled'
);
$form
[
'additional'
][
'states'
]
=
[
'#type'
=>
'checkboxes'
,
'#title'
=>
$this
->
t
(
'Send to CiviCRM'
),
'#options'
=>
[
WebformSubmissionInterface
::
STATE_DRAFT_CREATED
=>
$this
->
t
(
'…when <b>draft is created</b>.'
),
WebformSubmissionInterface
::
STATE_DRAFT_UPDATED
=>
$this
->
t
(
'…when <b>draft is updated</b>.'
),
WebformSubmissionInterface
::
STATE_CONVERTED
=>
$this
->
t
(
'…when anonymous <b>submission is converted</b> to authenticated.'
),
WebformSubmissionInterface
::
STATE_COMPLETED
=>
$this
->
t
(
'…when <b>submission is completed</b>.'
),
WebformSubmissionInterface
::
STATE_UPDATED
=>
$this
->
t
(
'…when <b>submission is updated</b>.'
),
WebformSubmissionInterface
::
STATE_DELETED
=>
$this
->
t
(
'…when <b>submission is deleted</b>.'
),
WebformSubmissionInterface
::
STATE_LOCKED
=>
$this
->
t
(
'…when <b>submission is locked</b>.'
),
],
'#access'
=>
$results_disabled
?
FALSE
:
TRUE
,
'#default_value'
=>
$results_disabled
?
[
WebformSubmissionInterface
::
STATE_COMPLETED
]
:
$this
->
configuration
[
'states'
],
];
if
(
$selected_formprocessor
)
{
$form
[
'additional'
][
'fields'
]
=
[
...
...
@@ -215,7 +240,12 @@ class FormProcessorWebformHandler extends WebformHandlerBase {
parent
::
submitConfigurationForm
(
$form
,
$form_state
);
$this
->
applyFormStateToConfiguration
(
$form_state
);
$values
=
$form_state
->
getValues
();
// Cleanup states.
$values
[
'states'
]
=
array_values
(
array_filter
(
$values
[
'states'
]));
$this
->
configuration
[
'connection'
]
=
$values
[
'connection'
];
$this
->
configuration
[
'states'
]
=
$values
[
'states'
];
$this
->
configuration
[
'form_processor'
]
=
$values
[
'form_processor'
];
$this
->
configuration
[
'form_processor_fields'
]
=
$values
[
'additional'
][
'fields'
];
$this
->
configuration
[
'form_processor_params'
]
=
[];
...
...
@@ -296,27 +326,58 @@ class FormProcessorWebformHandler extends WebformHandlerBase {
* {@inheritdoc}
*/
public
function
postSave
(
WebformSubmissionInterface
$webform_submission
,
$update
=
TRUE
,
$params
=
[])
{
$state
=
$webform_submission
->
getWebform
()
->
getSetting
(
'results_disabled'
)
?
WebformSubmissionInterface
::
STATE_COMPLETED
:
$webform_submission
->
getState
();
if
(
$this
->
configuration
[
'states'
]
&&
in_array
(
$state
,
$this
->
configuration
[
'states'
]))
{
$this
->
sendToCiviCRM
(
$webform_submission
);
}
}
/**
* {@inheritDoc}
*/
public
function
postDelete
(
WebformSubmissionInterface
$webform_submission
)
{
if
(
in_array
(
WebformSubmissionInterface
::
STATE_DELETED
,
$this
->
configuration
[
'states'
]))
{
$this
->
sendToCiviCRM
(
$webform_submission
);
}
}
/**
* @param \Drupal\webform\WebformSubmissionInterface $webform_submission
*/
private
function
sendToCiviCRM
(
WebformSubmissionInterface
$webform_submission
)
{
$data
=
$webform_submission
->
getData
();
$fields
=
$this
->
configuration
[
'form_processor_fields'
];
foreach
(
$fields
as
$key
=>
$field
){
if
(
key_exists
(
$key
,
$data
)){
if
(
isset
(
$data
[
$key
])
&&
in_array
(
$this
->
getWebform
()
->
getElement
(
$key
)[
'#type'
],[
'webform_document_file'
,
'managed_file'
,
'webform_image_file'
])){
$file
=
File
::
load
(
$data
[
$key
]);
$fileData
=
[
foreach
(
$fields
as
$key
=>
$field
)
{
if
(
key_exists
(
$key
,
$data
))
{
if
(
isset
(
$data
[
$key
])
&&
in_array
(
$this
->
getWebform
()
->
getElement
(
$key
)[
'#type'
],
[
'webform_document_file'
,
'managed_file'
,
'webform_image_file'
,
]))
{
$file
=
File
::
load
(
$data
[
$key
]);
$fileData
=
[
'name'
=>
$file
->
getFilename
(),
'mime_type'
=>
$file
->
getMimeType
(),
'content'
=>
base64_encode
(
file_get_contents
(
$file
->
getFileUri
()))
'content'
=>
base64_encode
(
file_get_contents
(
$file
->
getFileUri
()))
,
];
$params
[
$key
]
=
$fileData
;
}
else
{
}
else
{
$params
[
$key
]
=
$data
[
$key
];
}
}
}
if
(
$this
->
configuration
[
'form_processor_current_contact'
]){
$params
[
$this
->
configuration
[
'form_processor_current_contact'
]]
=
$this
->
getContactId
();
if
(
$this
->
configuration
[
'form_processor_current_contact'
])
{
$params
[
$this
->
configuration
[
'form_processor_current_contact'
]]
=
$this
->
getContactId
();
}
$call
=
$this
->
core
->
createCall
(
$this
->
configuration
[
'connection'
],
'FormProcessor'
,
$this
->
configuration
[
'form_processor'
],
$params
,[]);
$call
=
$this
->
core
->
createCall
(
$this
->
configuration
[
'connection'
],
'FormProcessor'
,
$this
->
configuration
[
'form_processor'
],
$params
,
[]
);
$this
->
core
->
executeCall
(
$call
);
}
...
...
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