From: Coleman Watts Date: Fri, 12 Nov 2021 14:44:26 +0000 (-0500) Subject: CiviGrant - Migrate component functions to hooks X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=be49cd8a5ebde959e12939bac5d03056894b44c5;p=civicrm-core.git CiviGrant - Migrate component functions to hooks --- diff --git a/ext/civigrant/CRM/Grant/Info.php b/ext/civigrant/CRM/Grant/Info.php deleted file mode 100644 index e4093715f3..0000000000 --- a/ext/civigrant/CRM/Grant/Info.php +++ /dev/null @@ -1,152 +0,0 @@ - 'CiviGrant', - 'translatedName' => ts('CiviGrant'), - 'title' => 'CiviCRM Grant Management Engine', - 'path' => 'CRM_Grant_', - 'search' => 1, - 'showActivitiesInCore' => 1, - ]; - } - - /** - * @inheritDoc - * @param bool $getAllUnconditionally - * @param bool $descriptions - * Whether to return permission descriptions - * - * @return array - */ - public function getPermissions($getAllUnconditionally = FALSE, $descriptions = FALSE) { - $permissions = [ - 'access CiviGrant' => [ - ts('access CiviGrant'), - ts('View all grants'), - ], - 'edit grants' => [ - ts('edit grants'), - ts('Create and update grants'), - ], - 'delete in CiviGrant' => [ - ts('delete in CiviGrant'), - ts('Delete grants'), - ], - ]; - - if (!$descriptions) { - foreach ($permissions as $name => $attr) { - $permissions[$name] = array_shift($attr); - } - } - - return $permissions; - } - - /** - * @inheritDoc - * @return null - */ - public function getUserDashboardElement() { - // no dashboard element for this component - return NULL; - } - - /** - * @inheritDoc - * @return null - */ - public function getUserDashboardObject() { - // no dashboard element for this component - return NULL; - } - - /** - * @inheritDoc - * @return array - */ - public function registerTab() { - return [ - 'title' => ts('Grants'), - 'url' => 'grant', - 'weight' => 60, - ]; - } - - /** - * @inheritDoc - * @return string - */ - public function getIcon() { - return 'crm-i fa-money'; - } - - /** - * @inheritDoc - * @return array - */ - public function registerAdvancedSearchPane() { - return [ - 'title' => ts('Grants'), - 'weight' => 50, - ]; - } - - /** - * @inheritDoc - * @return null - */ - public function getActivityTypes() { - return NULL; - } - - /** - * add shortcut to Create New. - * @param $shortCuts - */ - public function creatNewShortcut(&$shortCuts) { - if (CRM_Core_Permission::check('access CiviGrant') && - CRM_Core_Permission::check('edit grants') - ) { - $shortCuts = array_merge($shortCuts, [ - [ - 'path' => 'civicrm/grant/add', - 'query' => "reset=1&action=add&context=standalone", - 'ref' => 'new-grant', - 'title' => ts('Grant'), - ], - ]); - } - } - -} diff --git a/ext/civigrant/civigrant.php b/ext/civigrant/civigrant.php index 2732fed7ef..ba8748d5eb 100644 --- a/ext/civigrant/civigrant.php +++ b/ext/civigrant/civigrant.php @@ -31,3 +31,59 @@ function civigrant_civicrm_alterSettingsFolders(&$metaDataFolders = NULL) { function civigrant_civicrm_entityTypes(&$entityTypes) { _civigrant_civix_civicrm_entityTypes($entityTypes); } + +/** + * Implements hook_civicrm_links(). + * + * Add shortcut link to create new grant. + */ +function civigrant_civicrm_links($context, $name, $id, &$links) { + if ($context === 'create.new.shortcuts' && CRM_Core_Permission::check(['access CiviGrant', 'edit grants'])) { + $links[] = [ + 'path' => 'civicrm/grant/add', + 'query' => "reset=1&action=add&context=standalone", + 'ref' => 'new-grant', + 'title' => ts('Grant'), + ]; + } +} + +/** + * Implements hook_civicrm_permission(). + * + * Define CiviGrant permissions. + */ +function civigrant_civicrm_permission(&$permissions) { + $permissions['access CiviGrant'] = [ + E::ts('access CiviGrant'), + E::ts('View all grants'), + ]; + $permissions['edit grants'] = [ + E::ts('edit grants'), + E::ts('Create and update grants'), + ]; + $permissions['delete in CiviGrant'] = [ + E::ts('delete in CiviGrant'), + E::ts('Delete grants'), + ]; +} + +/** + * Implements hook_civicrm_tabSet(). + * + * Add grants tab to contact summary screen. + */ +function civigrant_civicrm_tabSet($tabSetName, &$tabs, $context) { + if ($tabSetName === 'civicrm/contact/view' && !empty($context['contact_id'])) { + $cid = $context['contact_id']; + $tabs[] = [ + 'id' => 'grant', + 'url' => CRM_Utils_System::url("civicrm/contact/view/grant", ['reset' => 1, 'cid' => $cid]), + 'title' => E::ts('Grants'), + 'weight' => 60, + 'count' => CRM_Grant_BAO_Grant::getContactGrantCount($cid), + 'class' => 'livePage', + 'icon' => 'crm-i fa-money', + ]; + } +}