|
3 | 3 | * NutshellModx FormIt hook
|
4 | 4 | *
|
5 | 5 | */
|
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 | +); |
7 | 16 | if (!($nutshellmodx instanceof NutshellModx)) {
|
8 | 17 | return;
|
9 | 18 | }
|
|
37 | 46 | // Set default lead note to contact emailaddress
|
38 | 47 | // Check if note field is set in config, if so, and form value is not empty, use that
|
39 | 48 | $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']])) { |
41 | 52 | $leadNote = $values[$formFields['lead.note']];
|
42 | 53 | }
|
43 | 54 |
|
|
47 | 58 | if (isset($findContact) && isset($findContact->contacts) && count($findContact->contacts)) {
|
48 | 59 | $contactId = $findContact->contacts[0]->id;
|
49 | 60 | } else {
|
| 61 | + $contactName = $values[$formFields['contact.email']]; |
| 62 | + if (isset($values[$formFields['contact.name']])) { |
| 63 | + $contactName = $values[$formFields['contact.name']]; |
| 64 | + } |
50 | 65 | $createContact = $nutshellmodx->callApi(
|
51 | 66 | 'newContact',
|
52 | 67 | [
|
53 | 68 | 'contact' => [
|
54 | 69 | 'email' => $values[$formFields['contact.email']],
|
55 |
| - 'name' => (isset($values[$formFields['contact.name']]) ? $values[$formFields['contact.name']] : $values[$formFields['contact.email']]), |
| 70 | + 'name' => $contactName |
56 | 71 | ]
|
57 | 72 | ]
|
58 | 73 | );
|
|
62 | 77 | }
|
63 | 78 |
|
64 | 79 | // Use the existing or newly created contactId
|
65 |
| -if ($contactId) { |
| 80 | +if (isset($contactId)) { |
66 | 81 | $accoundId = 0;
|
67 | 82 | $getContact = $nutshellmodx->callApi('getContact', ['contactId' => $contactId]);
|
68 | 83 | if ($getContact) {
|
|
75 | 90 | // If account name is set, try to find the company via the API
|
76 | 91 | // When not found, create new company account
|
77 | 92 | 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 | + ); |
79 | 97 | if ($searchAccounts && count($searchAccounts)) {
|
80 | 98 | $accountId = $searchAccounts[0]->id;
|
81 | 99 | } else {
|
|
0 commit comments