Avoid malformed 'Individual' call to api3
Overview
Passing in $custom_group['extends']
as the entity within PreData.php can trigger a malformed call to APIv3 where, instead of using the Contact entity, will attempt to use 'Individual'.
Details Error message
CRM_Core_Exception: Malformed name in civicrm_api3() (line 135 of civicrm/api/api.php).
Variable details at time of error
$action: 'getsingle'
$entity: 'Individual'
$result["error_code"]: 'not-found'
$result['error_message']: "API (Individual, get) does not exist (join the API team and implement it!)"
Backtrace
civicrm_api3 ([webroot]/sites/all/modules/civicrm/api/api.php:135)
CRM_Civirules_Utils_PreData::customPre ([webroot]/sites/all/civicrm-custom/extensions/org.civicoop.civirules/CRM/Civirules/Utils/PreData.php:108)
civirules_civicrm_customPre ([webroot]/sites/all/civicrm-custom/extensions/org.civicoop.civirules/civirules.php:468)
CRM_Utils_Hook->runHooks ([webroot]/sites/all/modules/civicrm/CRM/Utils/Hook.php:284)
CRM_Utils_Hook_DrupalBase->invokeViaUF ([webroot]/sites/all/modules/civicrm/CRM/Utils/Hook/DrupalBase.php:73)
Civi\Core\CiviEventDispatcher::delegateToUF ([webroot]/sites/all/modules/civicrm/Civi/Core/CiviEventDispatcher.php:322)
Symfony\Component\EventDispatcher\EventDispatcher->callListeners ([webroot]/sites/all/modules/civicrm/vendor/symfony/event-dispatcher/EventDispatcher.php:251)
Symfony\Component\EventDispatcher\EventDispatcher->dispatch ([webroot]/sites/all/modules/civicrm/vendor/symfony/event-dispatcher/EventDispatcher.php:73)
Civi\Core\CiviEventDispatcher->dispatch ([webroot]/sites/all/modules/civicrm/Civi/Core/CiviEventDispatcher.php:263)
CRM_Utils_Hook->invoke ([webroot]/sites/all/modules/civicrm/CRM/Utils/Hook.php:168)
CRM_Utils_Hook::customPre ([webroot]/sites/all/modules/civicrm/CRM/Utils/Hook.php:564)
CRM_Core_BAO_CustomValueTable::create ([webroot]/sites/all/modules/civicrm/CRM/Core/BAO/CustomValueTable.php:67)
CRM_Core_BAO_CustomValueTable::store ([webroot]/sites/all/modules/civicrm/CRM/Core/BAO/CustomValueTable.php:407)
CRM_Contact_BAO_Contact::create ([webroot]/sites/all/modules/civicrm/CRM/Contact/BAO/Contact.php:384)
_civicrm_api3_contact_update ([webroot]/sites/all/modules/civicrm/api/v3/Contact.php:571)
civicrm_api3_contact_create ([webroot]/sites/all/modules/civicrm/api/v3/Contact.php:99)
Civi\API\Provider\MagicFunctionProvider->invoke ([webroot]/sites/all/modules/civicrm/Civi/API/Provider/MagicFunctionProvider.php:89)
Civi\API\Kernel->runRequest ([webroot]/sites/all/modules/civicrm/Civi/API/Kernel.php:158)
Civi\API\Kernel->runSafe ([webroot]/sites/all/modules/civicrm/Civi/API/Kernel.php:81)
civicrm_api ([webroot]/sites/all/modules/civicrm/api/api.php:22)
After
With this PR, the $entity
passed to the API call is set the custom group's extended entity, to ensure that an 'Individual' custom group returns 'Contact' for the sake of the call.
Edited by brienne