Remove reference to CiviAuction
[civicrm-core.git] / Civi / Api4 / Action / Contact / ContactSaveTrait.php
1 <?php
2
3 /*
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC. All rights reserved. |
6 | |
7 | This work is published under the GNU AGPLv3 license with some |
8 | permitted exceptions and without any warranty. For full license |
9 | and copyright information, see https://civicrm.org/licensing |
10 +--------------------------------------------------------------------+
11 */
12
13 namespace Civi\Api4\Action\Contact;
14
15 /**
16 * Code shared by Contact create/update/save actions
17 */
18 trait ContactSaveTrait {
19
20 /**
21 * @param array $items
22 * @return array
23 */
24 protected function write(array $items) {
25 foreach ($items as &$contact) {
26 // For some reason the contact BAO requires this for updates
27 if (!empty($contact['id'])) {
28 $contact['contact_id'] = $contact['id'];
29 }
30 elseif (empty($contact['contact_type'])) {
31 // Guess which type of contact is being created
32 if (!empty($contact['organization_name'])) {
33 $contact['contact_type'] = 'Organization';
34 }
35 elseif (!empty($contact['household_name'])) {
36 $contact['contact_type'] = 'Household';
37 }
38 else {
39 $contact['contact_type'] = 'Individual';
40 }
41 }
42 }
43 return parent::write($items);
44 }
45
46 }