* array of Pcp if found
*/
public static function getPcpDashboardInfo($contactId) {
- $links = self::pcpLinks();
-
$query = '
SELECT pcp.*, block.is_tellfriend_enabled FROM civicrm_pcp pcp
LEFT JOIN civicrm_pcp_block block ON block.id = pcp.pcp_block_id
ORDER BY page_type, page_id';
$params = [1 => [$contactId, 'Integer']];
-
$pcpInfoDao = CRM_Core_DAO::executeQuery($query, $params);
- $pcpInfo = [];
- $hide = $mask = array_sum(array_keys($links['all']));
- $contactPCPPages = [];
+ $links = self::pcpLinks();
+ $hide = $mask = array_sum(array_keys($links['all']));
$approved = CRM_Core_PseudoConstant::getKey('CRM_PCP_BAO_PCP', 'status_id', 'Approved');
+ $contactPCPPages = [];
+ $pcpInfo = [];
while ($pcpInfoDao->fetch()) {
$mask = $hide;
/**
* Get action links.
*
+ * @param int $pcpId
+ * Contains the pcp ID. Defaults to NULL for backwards compatibility.
+ *
* @return array
* (reference) of action links
*/
- public static function &pcpLinks() {
+ public static function &pcpLinks($pcpId = NULL) {
if (!(self::$_pcpLinks)) {
$deleteExtra = ts('Are you sure you want to delete this Personal Campaign Page?') . '\n' . ts('This action cannot be undone.');
'title' => ts('Delete'),
],
];
+
+ CRM_Utils_Hook::links('pcp.user.actions', 'Pcp', $pcpId, self::$_pcpLinks);
}
return self::$_pcpLinks;
}
], CRM_PCP_BAO_PCP::getPcpDashboardInfo($contactID));
}
+ /**
+ * Test that hook_civicrm_links is called.
+ */
+ public function testPcpInfoLinksHook() {
+ Civi::dispatcher()->addListener('hook_civicrm_links', [$this, 'hookLinks']);
+
+ // Reset the cache otherwise our hook will not be called
+ CRM_PCP_BAO_PCP::$_pcpLinks = NULL;
+
+ $block = CRM_PCP_BAO_PCPBlock::create($this->pcpBlockParams());
+ $contactID = $this->individualCreate();
+ $contributionPage = $this->callAPISuccessGetSingle('ContributionPage', []);
+ $pcp = $this->callAPISuccess('Pcp', 'create', ['contact_id' => $contactID, 'title' => 'pcp', 'page_id' => $contributionPage['id'], 'pcp_block_id' => $block->id, 'is_active' => TRUE, 'status_id' => 'Approved']);
+
+ $links = CRM_PCP_BAO_PCP::pcplinks($pcp['id']);
+
+ foreach ($links['all'] as $link) {
+ if ($link['name'] == 'URL for this Page') {
+ $found = TRUE;
+ $this->assertEquals($link['url'], 'https://civicrm.org/mih');
+ }
+ }
+
+ $this->assertEquals($found, TRUE);
+ }
+
+ /**
+ * This is the listener for hook_civicrm_links
+ *
+ * Replaces the "URL for this Page" link by a hardcoded link.
+ * This is the listener for hook_civicrm_alterReportVar
+ *
+ * @param \Civi\Core\Event\GenericHookEvent $e
+ * Should contain 'op', 'links', and other members corresponding
+ * to the hook parameters.
+ */
+ public function hookLinks(\Civi\Core\Event\GenericHookEvent $e) {
+ if ($e->op == 'pcp.user.actions') {
+ foreach ($e->links['all'] as $key => &$link) {
+ if ($link['name'] == 'URL for this Page') {
+ $e->links['all'][$key]['url'] = 'https://civicrm.org/mih';
+ }
+ }
+ }
+ }
+
/**
* Test that CRM_Contribute_BAO_Contribution::_gatherMessageValues() works
* with PCP.