Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
webform_pipedrive
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
webform_pipedrive
Commits
1310ebed
Commit
1310ebed
authored
2 months ago
by
Nikhil Dawar
Committed by
Simran Dev Yadav
2 months ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3508411
by nikhil_dawar: Compatibility with php 8.4 version
parent
97413e14
Branches
Branches containing commit
No related tags found
1 merge request
!3
compatibility with php 8.4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Plugin/WebformHandler/WebformPipedrive.php
+56
-42
56 additions, 42 deletions
src/Plugin/WebformHandler/WebformPipedrive.php
webform_pipedrive.info.yml
+1
-1
1 addition, 1 deletion
webform_pipedrive.info.yml
with
57 additions
and
43 deletions
src/Plugin/WebformHandler/WebformPipedrive.php
+
56
−
42
View file @
1310ebed
...
@@ -2,9 +2,12 @@
...
@@ -2,9 +2,12 @@
namespace
Drupal\webform_pipedrive\Plugin\WebformHandler
;
namespace
Drupal\webform_pipedrive\Plugin\WebformHandler
;
use
Drupal\Core\Entity\EntityFieldManagerInterface
;
use
Drupal\Core\Form\FormStateInterface
;
use
Drupal\Core\Form\FormStateInterface
;
use
Drupal\Core\Language\LanguageManagerInterface
;
use
Drupal\webform\Plugin\WebformHandlerBase
;
use
Drupal\webform\Plugin\WebformHandlerBase
;
use
Drupal\webform\WebformSubmissionInterface
;
use
Drupal\webform\WebformSubmissionInterface
;
use
GuzzleHttp\ClientInterface
;
use
GuzzleHttp\Exception\RequestException
;
use
GuzzleHttp\Exception\RequestException
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
...
@@ -15,13 +18,10 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
...
@@ -15,13 +18,10 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
* id = "webform_pipedrive",
* id = "webform_pipedrive",
* label = @Translation("WebformPipedrive"),
* label = @Translation("WebformPipedrive"),
* category = @Translation("WebformPipedrive"),
* category = @Translation("WebformPipedrive"),
* description = @Translation("Send the values to the api on
* description = @Translation("Send the values to the api on form submission."),
* form submission."), cardinality =
* cardinality = \Drupal\webform\Plugin\WebformHandlerInterface::CARDINALITY_UNLIMITED,
* \Drupal\webform\Plugin\WebformHandlerInterface::CARDINALITY_UNLIMITED,
* results = \Drupal\webform\Plugin\WebformHandlerInterface::RESULTS_PROCESSED,
* results =
* submission = \Drupal\webform\Plugin\WebformHandlerInterface::SUBMISSION_OPTIONAL,
* \Drupal\webform\Plugin\WebformHandlerInterface::RESULTS_PROCESSED,
* submission =
* \Drupal\webform\Plugin\WebformHandlerInterface::SUBMISSION_OPTIONAL,
* tokens = TRUE,
* tokens = TRUE,
* )
* )
*/
*/
...
@@ -32,29 +32,37 @@ class WebformPipedrive extends WebformHandlerBase {
...
@@ -32,29 +32,37 @@ class WebformPipedrive extends WebformHandlerBase {
*
*
* @var \Drupal\Core\Entity\EntityFieldManagerInterface
* @var \Drupal\Core\Entity\EntityFieldManagerInterface
*/
*/
protected
$entityFieldManager
;
protected
EntityFieldManagerInterface
$entityFieldManager
;
/**
/**
* The language Manager.
* The language Manager.
*
*
* @var \Drupal\Core\Language\LanguageManagerInterface
* @var \Drupal\Core\Language\LanguageManagerInterface
*/
*/
protected
$languageManager
;
protected
LanguageManagerInterface
$languageManager
;
/**
* The HTTP client.
*
* @var \GuzzleHttp\ClientInterface
*/
protected
ClientInterface
$httpClient
;
/**
/**
* {@inheritdoc}
* {@inheritdoc}
*/
*/
public
static
function
create
(
ContainerInterface
$container
,
array
$configuration
,
$plugin_id
,
$plugin_definition
)
{
public
static
function
create
(
ContainerInterface
$container
,
array
$configuration
,
$plugin_id
,
$plugin_definition
)
:
self
{
$plugin
=
parent
::
create
(
$container
,
$configuration
,
$plugin_id
,
$plugin_definition
);
$plugin
=
parent
::
create
(
$container
,
$configuration
,
$plugin_id
,
$plugin_definition
);
$plugin
->
entityFieldManager
=
$container
->
get
(
'entity_field.manager'
);
$plugin
->
entityFieldManager
=
$container
->
get
(
'entity_field.manager'
);
$plugin
->
languageManager
=
$container
->
get
(
'language_manager'
);
$plugin
->
languageManager
=
$container
->
get
(
'language_manager'
);
$plugin
->
httpClient
=
$container
->
get
(
'http_client'
);
return
$plugin
;
return
$plugin
;
}
}
/**
/**
* {@inheritdoc}
* {@inheritdoc}
*/
*/
public
function
defaultConfiguration
()
{
public
function
defaultConfiguration
()
:
array
{
return
[
return
[
'enable_mapping'
=>
FALSE
,
'enable_mapping'
=>
FALSE
,
'enable_orgdeals'
=>
FALSE
,
'enable_orgdeals'
=>
FALSE
,
...
@@ -67,8 +75,7 @@ class WebformPipedrive extends WebformHandlerBase {
...
@@ -67,8 +75,7 @@ class WebformPipedrive extends WebformHandlerBase {
/**
/**
* {@inheritdoc}
* {@inheritdoc}
*/
*/
public
function
buildConfigurationForm
(
array
$form
,
FormStateInterface
$form_state
)
{
public
function
buildConfigurationForm
(
array
$form
,
FormStateInterface
$form_state
):
array
{
$mapping_options
=
$this
->
getMappingOptions
();
$mapping_options
=
$this
->
getMappingOptions
();
// Checkbox to enable or disable mapping.
// Checkbox to enable or disable mapping.
...
@@ -173,12 +180,10 @@ class WebformPipedrive extends WebformHandlerBase {
...
@@ -173,12 +180,10 @@ class WebformPipedrive extends WebformHandlerBase {
/**
/**
* {@inheritdoc}
* {@inheritdoc}
*
* Validate the configuration form.
*/
*/
public
function
validateConfigurationForm
(
array
&
$form
,
FormStateInterface
$form_state
)
{
public
function
validateConfigurationForm
(
array
&
$form
,
FormStateInterface
$form_state
):
void
{
parent
::
validateConfigurationForm
(
$form
,
$form_state
);
parent
::
validateConfigurationForm
(
$form
,
$form_state
);
// Validate Person field mapping.
// Validate Person field mapping.
if
(
empty
(
$form_state
->
getValue
(
'user_field_mapping'
)))
{
if
(
empty
(
$form_state
->
getValue
(
'user_field_mapping'
)))
{
$form_state
->
setErrorByName
(
'user_field_mapping'
,
$this
->
t
(
'At least one Person mapping field must be selected.'
));
$form_state
->
setErrorByName
(
'user_field_mapping'
,
$this
->
t
(
'At least one Person mapping field must be selected.'
));
...
@@ -198,47 +203,46 @@ class WebformPipedrive extends WebformHandlerBase {
...
@@ -198,47 +203,46 @@ class WebformPipedrive extends WebformHandlerBase {
/**
/**
* {@inheritdoc}
* {@inheritdoc}
*
* Submit the configuration form.
*/
*/
public
function
submitConfigurationForm
(
array
&
$form
,
FormStateInterface
$form_state
)
{
public
function
submitConfigurationForm
(
array
&
$form
,
FormStateInterface
$form_state
)
:
void
{
parent
::
submitConfigurationForm
(
$form
,
$form_state
);
parent
::
submitConfigurationForm
(
$form
,
$form_state
);
// You can access form values like this:
$tokenized_text
=
$form_state
->
getValue
([
'settings'
,
'tokenized_text'
]);
// You can access form values like this:
$tokenized_text
=
$form_state
->
getValue
([
'settings'
,
'tokenized_text'
]);
$user_field_mapping
=
$form_state
->
getValue
([
'settings'
,
'user_field_mapping'
]);
$user_field_mapping
=
$form_state
->
getValue
([
'settings'
,
'user_field_mapping'
]);
// Optionally, save the custom configuration values to the handler.
// Optionally, save the custom configuration values to the handler.
$this
->
configuration
[
'tokenized_text'
]
=
$tokenized_text
;
$this
->
configuration
[
'tokenized_text'
]
=
$tokenized_text
;
$this
->
configuration
[
'user_field_mapping'
]
=
$user_field_mapping
;
$this
->
configuration
[
'user_field_mapping'
]
=
$user_field_mapping
;
$this
->
applyFormStateToConfiguration
(
$form_state
);
$this
->
applyFormStateToConfiguration
(
$form_state
);
}
}
/**
/**
* {@inheritdoc}
* {@inheritdoc}
*
* Send data to Pipedrive after form submission.
*/
*/
public
function
postSave
(
WebformSubmissionInterface
$webform_submission
,
$update
=
TRUE
)
{
public
function
postSave
(
WebformSubmissionInterface
$webform_submission
,
$update
=
TRUE
)
:
void
{
// Fetch submission data and configuration settings.
// Fetch submission data and configuration settings.
$webform_data
=
$webform_submission
->
getData
();
$webform_data
=
$webform_submission
->
getData
();
$user_field_mapping
=
$this
->
configuration
[
'user_field_mapping'
];
$user_field_mapping
=
$this
->
configuration
[
'user_field_mapping'
];
$enableMapping
=
$this
->
configuration
[
'enable_mapping'
];
$enableMapping
=
$this
->
configuration
[
'enable_mapping'
];
$enable_deals
=
$this
->
configuration
[
'enable_deals'
];
$enable_deals
=
$this
->
configuration
[
'enable_deals'
];
$enable_orgdeals
=
$this
->
configuration
[
'enable_orgdeals'
];
$enable_orgdeals
=
$this
->
configuration
[
'enable_orgdeals'
];
// To get configuration for the pipedrive from service.
// To get configuration for the pipedrive from service.
$configsettings
=
\Drupal
::
service
(
'webform_pipedrive.get_access_token'
)
->
accessToken
();
$configsettings
=
\Drupal
::
service
(
'webform_pipedrive.get_access_token'
)
->
accessToken
();
$endPoint
=
$configsettings
[
'endpoint'
];
$endPoint
=
$configsettings
[
'endpoint'
];
$accessToken
=
$configsettings
[
'accessToken'
];
$accessToken
=
$configsettings
[
'accessToken'
];
$orgId
=
0
;
$orgId
=
0
;
$user_field_mapping_org
=
[];
$user_field_mapping_org
=
[];
// Initialize the formatted output.
// Initialize the formatted output.
$formatted_output
=
''
;
$formatted_output
=
''
;
// Format the submission values as key: value pairs with new lines.
// Format the submission values as key: value pairs with new lines.
foreach
(
$webform_data
as
$key
=>
$value
)
{
foreach
(
$webform_data
as
$key
=>
$value
)
{
$formatted_output
.
=
ucfirst
(
str_replace
(
'_'
,
' '
,
$key
))
.
': '
.
$value
.
"
\n
"
;
$formatted_output
.
=
ucfirst
(
str_replace
(
'_'
,
' '
,
$key
))
.
': '
.
$value
.
"
\n
"
;
}
}
// Replace the token in the tokenized text.
// Replace the token in the tokenized text.
$token_service
=
\Drupal
::
token
();
$token_service
=
\Drupal
::
token
();
$replaced_text
=
$token_service
->
replace
(
$this
->
configuration
[
'tokenized_text'
][
'value'
],
[
'webform_submission'
=>
$webform_submission
]);
$replaced_text
=
$token_service
->
replace
(
$this
->
configuration
[
'tokenized_text'
][
'value'
],
[
'webform_submission'
=>
$webform_submission
]);
...
@@ -249,13 +253,14 @@ class WebformPipedrive extends WebformHandlerBase {
...
@@ -249,13 +253,14 @@ class WebformPipedrive extends WebformHandlerBase {
// Process organization data.
// Process organization data.
$orgData
=
[];
$orgData
=
[];
if
(
$enableMapping
!=
FALSE
)
{
if
(
$enableMapping
)
{
$user_field_mapping_org
=
$this
->
configuration
[
'user_field_mapping_org'
];
$user_field_mapping_org
=
$this
->
configuration
[
'user_field_mapping_org'
];
foreach
(
$user_field_mapping_org
as
$webform_key
=>
$user_field
)
{
foreach
(
$user_field_mapping_org
as
$webform_key
=>
$user_field
)
{
$orgData
[
$user_field
]
=
$webform_data
[
$webform_key
];
$orgData
[
$user_field
]
=
$webform_data
[
$webform_key
];
}
}
$orgId
=
\Drupal
::
service
(
'webform_pipedrive.pipe_drive_integration'
)
->
sentWebformSubmissionToPipeDriveForOrganisation
(
$orgData
,
$accessToken
,
$endPoint
);
$orgId
=
\Drupal
::
service
(
'webform_pipedrive.pipe_drive_integration'
)
->
sentWebformSubmissionToPipeDriveForOrganisation
(
$orgData
,
$accessToken
,
$endPoint
);
}
}
// Process person data.
// Process person data.
$personData
=
[];
$personData
=
[];
$personData
[
'org_id'
]
=
$orgId
;
$personData
[
'org_id'
]
=
$orgId
;
...
@@ -272,7 +277,7 @@ class WebformPipedrive extends WebformHandlerBase {
...
@@ -272,7 +277,7 @@ class WebformPipedrive extends WebformHandlerBase {
* @return array
* @return array
* Array of source and destination options.
* Array of source and destination options.
*/
*/
protected
function
getMappingOptions
()
{
protected
function
getMappingOptions
()
:
array
{
// Get all Webform elements.
// Get all Webform elements.
$webform
=
$this
->
getWebform
();
$webform
=
$this
->
getWebform
();
$elements
=
$webform
->
getElementsInitializedFlattenedAndHasValue
();
$elements
=
$webform
->
getElementsInitializedFlattenedAndHasValue
();
...
@@ -280,9 +285,11 @@ class WebformPipedrive extends WebformHandlerBase {
...
@@ -280,9 +285,11 @@ class WebformPipedrive extends WebformHandlerBase {
foreach
(
$elements
as
$key
=>
$element
)
{
foreach
(
$elements
as
$key
=>
$element
)
{
$source_options
[
$key
]
=
$element
[
'#admin_title'
]
?:
$element
[
'#title'
]
?:
$key
;
$source_options
[
$key
]
=
$element
[
'#admin_title'
]
?:
$element
[
'#title'
]
?:
$key
;
}
}
// Fetch dynamic Pipedrive fields from the API.
// Fetch dynamic Pipedrive fields from the API.
$destination_options
=
$this
->
fetchPipedriveFields
();
$destination_options
=
$this
->
fetchPipedriveFields
();
$orgdestination_options
=
$this
->
fetchorgPipedriveFields
();
$orgdestination_options
=
$this
->
fetchOrgPipedriveFields
();
return
[
return
[
'source'
=>
$source_options
,
'source'
=>
$source_options
,
'destination'
=>
$destination_options
,
'destination'
=>
$destination_options
,
...
@@ -292,10 +299,11 @@ class WebformPipedrive extends WebformHandlerBase {
...
@@ -292,10 +299,11 @@ class WebformPipedrive extends WebformHandlerBase {
/**
/**
* Fetch the available Pipedrive fields from the API dynamically.
* Fetch the available Pipedrive fields from the API dynamically.
*
* @return array
* Array of Pipedrive fields.
*/
*/
protected
function
fetchPipedriveFields
()
{
protected
function
fetchPipedriveFields
():
array
{
$client
=
\Drupal
::
service
(
'http_client'
);
// To get configuration for the Pipedrive from the service.
// To get configuration for the Pipedrive from the service.
$configsettings
=
\Drupal
::
service
(
'webform_pipedrive.get_access_token'
)
->
accessToken
();
$configsettings
=
\Drupal
::
service
(
'webform_pipedrive.get_access_token'
)
->
accessToken
();
$endPoint
=
$configsettings
[
'endpoint'
];
$endPoint
=
$configsettings
[
'endpoint'
];
...
@@ -304,7 +312,7 @@ class WebformPipedrive extends WebformHandlerBase {
...
@@ -304,7 +312,7 @@ class WebformPipedrive extends WebformHandlerBase {
$url
=
$endPoint
.
'/v1/personFields?api_token='
.
$accessToken
;
$url
=
$endPoint
.
'/v1/personFields?api_token='
.
$accessToken
;
try
{
try
{
$response
=
$
c
lient
->
get
(
$url
);
$response
=
$
this
->
httpC
lient
->
get
(
$url
);
$response_body
=
$response
->
getBody
()
->
getContents
();
$response_body
=
$response
->
getBody
()
->
getContents
();
$data
=
json_decode
(
$response_body
,
TRUE
);
$data
=
json_decode
(
$response_body
,
TRUE
);
...
@@ -326,18 +334,23 @@ class WebformPipedrive extends WebformHandlerBase {
...
@@ -326,18 +334,23 @@ class WebformPipedrive extends WebformHandlerBase {
/**
/**
* Fetch the available Pipedrive organization fields from the API dynamically.
* Fetch the available Pipedrive organization fields from the API dynamically.
*
* @return array
* Array of Pipedrive organization fields.
*/
*/
protected
function
fetchOrgPipedriveFields
()
{
protected
function
fetchOrgPipedriveFields
():
array
{
$client
=
\Drupal
::
service
(
'http_client'
);
// To get configuration for the Pipedrive from the service.
// To get configuration for the Pipedrive from the service.
$configsettings
=
\Drupal
::
service
(
'webform_pipedrive.get_access_token'
)
->
accessToken
();
$configsettings
=
\Drupal
::
service
(
'webform_pipedrive.get_access_token'
)
->
accessToken
();
$endPoint
=
$configsettings
[
'endpoint'
];
$endPoint
=
$configsettings
[
'endpoint'
];
$accessToken
=
$configsettings
[
'accessToken'
];
$accessToken
=
$configsettings
[
'accessToken'
];
$url
=
$endPoint
.
'/v1/organizationFields?api_token='
.
$accessToken
;
$url
=
$endPoint
.
'/v1/organizationFields?api_token='
.
$accessToken
;
try
{
try
{
$response
=
$
c
lient
->
get
(
$url
);
$response
=
$
this
->
httpC
lient
->
get
(
$url
);
$response_body
=
$response
->
getBody
()
->
getContents
();
$response_body
=
$response
->
getBody
()
->
getContents
();
$data
=
json_decode
(
$response_body
,
TRUE
);
$data
=
json_decode
(
$response_body
,
TRUE
);
if
(
isset
(
$data
[
'data'
])
&&
is_array
(
$data
[
'data'
]))
{
if
(
isset
(
$data
[
'data'
])
&&
is_array
(
$data
[
'data'
]))
{
$destination_options
=
[];
$destination_options
=
[];
foreach
(
$data
[
'data'
]
as
$field
)
{
foreach
(
$data
[
'data'
]
as
$field
)
{
...
@@ -349,6 +362,7 @@ class WebformPipedrive extends WebformHandlerBase {
...
@@ -349,6 +362,7 @@ class WebformPipedrive extends WebformHandlerBase {
catch
(
RequestException
$e
)
{
catch
(
RequestException
$e
)
{
\Drupal
::
logger
(
'webform_pipedrive'
)
->
error
(
'Error fetching Pipedrive fields: '
.
$e
->
getMessage
());
\Drupal
::
logger
(
'webform_pipedrive'
)
->
error
(
'Error fetching Pipedrive fields: '
.
$e
->
getMessage
());
}
}
// Return empty array if there is an error fetching fields.
// Return empty array if there is an error fetching fields.
return
[];
return
[];
}
}
...
...
This diff is collapsed.
Click to expand it.
webform_pipedrive.info.yml
+
1
−
1
View file @
1310ebed
...
@@ -2,7 +2,7 @@ name: Webform Integration Pipedrive
...
@@ -2,7 +2,7 @@ name: Webform Integration Pipedrive
type
:
module
type
:
module
description
:
Use to connect webform with pipedrive API and configuration for API
description
:
Use to connect webform with pipedrive API and configuration for API
package
:
Webform
package
:
Webform
core_version_requirement
:
^9 || ^10
core_version_requirement
:
^9 || ^10
|| ^11
dependencies
:
dependencies
:
-
webform:webform
-
webform:webform
configure
:
webform_pipedrive.config
configure
:
webform_pipedrive.config
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