Skip to content

Commit 19fd47f

Browse files
committed
Fix isset bug + fix coding standards
1 parent bbf5c03 commit 19fd47f

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

core/components/nutshellmodx/elements/snippets/nutshellmodxhook.snippet.php

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,16 @@
33
* NutshellModx FormIt hook
44
*
55
*/
6-
$nutshellmodx = $modx->getService('nutshellmodx', 'NutshellModx', $modx->getOption('nutshellmodx.core_path', null, $modx->getOption('core_path').'components/nutshellmodx/').'model/nutshellmodx/', array());
6+
$nutshellmodx = $modx->getService(
7+
'nutshellmodx',
8+
'NutshellModx',
9+
$modx->getOption(
10+
'nutshellmodx.core_path',
11+
null,
12+
$modx->getOption('core_path').'components/nutshellmodx/'
13+
).'model/nutshellmodx/',
14+
array()
15+
);
716
if (!($nutshellmodx instanceof NutshellModx)) {
817
return;
918
}
@@ -37,7 +46,9 @@
3746
// Set default lead note to contact emailaddress
3847
// Check if note field is set in config, if so, and form value is not empty, use that
3948
$leadNote = $values[$formFields['contact.email']];
40-
if (isset($formFields['lead.note']) && isset($values[$formFields['lead.note']]) && !empty($values[$formFields['lead.note']])) {
49+
if (isset($formFields['lead.note'])
50+
&& isset($values[$formFields['lead.note']])
51+
&& !empty($values[$formFields['lead.note']])) {
4152
$leadNote = $values[$formFields['lead.note']];
4253
}
4354

@@ -47,12 +58,16 @@
4758
if (isset($findContact) && isset($findContact->contacts) && count($findContact->contacts)) {
4859
$contactId = $findContact->contacts[0]->id;
4960
} else {
61+
$contactName = $values[$formFields['contact.email']];
62+
if (isset($values[$formFields['contact.name']])) {
63+
$contactName = $values[$formFields['contact.name']];
64+
}
5065
$createContact = $nutshellmodx->callApi(
5166
'newContact',
5267
[
5368
'contact' => [
5469
'email' => $values[$formFields['contact.email']],
55-
'name' => (isset($values[$formFields['contact.name']]) ? $values[$formFields['contact.name']] : $values[$formFields['contact.email']]),
70+
'name' => $contactName
5671
]
5772
]
5873
);
@@ -62,7 +77,7 @@
6277
}
6378

6479
// Use the existing or newly created contactId
65-
if ($contactId) {
80+
if (isset($contactId)) {
6681
$accoundId = 0;
6782
$getContact = $nutshellmodx->callApi('getContact', ['contactId' => $contactId]);
6883
if ($getContact) {
@@ -75,7 +90,10 @@
7590
// If account name is set, try to find the company via the API
7691
// When not found, create new company account
7792
if ($values[$formFields['account.name']] && !empty($values[$formFields['account.name']])) {
78-
$searchAccounts = $nutshellmodx->callApi('searchAccounts', ['string' => $values[$formFields['account.name']]]);
93+
$searchAccounts = $nutshellmodx->callApi(
94+
'searchAccounts',
95+
['string' => $values[$formFields['account.name']]]
96+
);
7997
if ($searchAccounts && count($searchAccounts)) {
8098
$accountId = $searchAccounts[0]->id;
8199
} else {

0 commit comments

Comments
 (0)