4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC. All rights reserved. |
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 +--------------------------------------------------------------------+
13 namespace Civi\Api4\Action\Contact
;
16 * Code shared by Contact create/update/save actions
18 trait ContactSaveTrait
{
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'];
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';
35 elseif (!empty($contact['household_name'])) {
36 $contact['contact_type'] = 'Household';
39 $contact['contact_type'] = 'Individual';
43 return parent
::write($items);