'); * * Both values must be set or the tab renders a help banner explaining what * to configure. See README.md. */ /** * Resolve the app URL from constant or env. Empty string when unset. */ function _webform_mw_app_url(): string { if (defined('WEBFORM_MW_APP_URL')) { return rtrim((string) constant('WEBFORM_MW_APP_URL'), '/'); } $env = getenv('WEBFORM_MW_APP_URL'); return is_string($env) && $env !== '' ? rtrim($env, '/') : ''; } /** * Resolve the staff secret from constant or env. Empty string when unset. */ function _webform_mw_staff_key(): string { if (defined('WEBFORM_MW_STAFF_KEY')) { return (string) constant('WEBFORM_MW_STAFF_KEY'); } $env = getenv('WEBFORM_MW_STAFF_KEY'); return is_string($env) ? $env : ''; } /** * Implements hook_civicrm_tabset(). * * Adds the Engagement Report tab to the Organization contact summary tabset. * Other contact types (Individual, Household) get no tab. */ function webform_mw_civicrm_tabset($tabsetName, &$tabs, $context) { if ($tabsetName !== 'civicrm/contact/view') { return; } $cid = $context['contact_id'] ?? NULL; if (!$cid) { return; } // Restrict to Organization contacts. $contactType = NULL; try { $contactType = civicrm_api3('Contact', 'getvalue', [ 'id' => (int) $cid, 'return' => 'contact_type', ]); } catch (\Throwable $e) { // Quietly skip — failing here should not break the contact page. return; } if ($contactType !== 'Organization') { return; } $tabs[] = [ 'id' => 'engagement_report', 'title' => ts('Engagement Report'), 'weight' => 200, 'count' => NULL, 'icon' => 'crm-i fa-line-chart', 'url' => CRM_Utils_System::url( 'civicrm/contact/view/engagement-report', "reset=1&cid={$cid}&snippet=1" ), ]; }