X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=ext%2Ffinancialacls%2Ffinancialacls.php;h=c039ef1998f005ea1017a53063f79f69c24af753;hb=7f57015a5f2683650e8b4aa51bd8b849f4712e19;hp=7c8e7e4eb46c56a0b315ec0f91572456bddaa8d4;hpb=54cded939811cd6fa6c14f43976890ac7f779607;p=civicrm-core.git diff --git a/ext/financialacls/financialacls.php b/ext/financialacls/financialacls.php index 7c8e7e4eb4..c039ef1998 100644 --- a/ext/financialacls/financialacls.php +++ b/ext/financialacls/financialacls.php @@ -214,6 +214,62 @@ function financialacls_civicrm_buildAmount($component, $form, &$feeBlock) { } } +/** + * Remove unpermitted membership types from selection availability.. + * + * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_membershipTypeValues + * + * @param \CRM_Core_Form $form + * @param array $membershipTypeValues + */ +function financialacls_civicrm_membershipTypeValues($form, &$membershipTypeValues) { + $financialTypes = NULL; + $financialTypes = CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes, CRM_Core_Action::ADD); + foreach ($membershipTypeValues as $id => $type) { + if (!isset($financialTypes[$type['financial_type_id']])) { + unset($membershipTypeValues[$id]); + } + } +} + +/** + * Remove unpermitted financial types from field Options in search context. + * + * Search context is described as + * 'search' => "search: searchable options are returned; labels are translated.", + * So this is appropriate to removing the options from search screens. + * + * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_fieldOptions + * + * @param string $entity + * @param string $field + * @param array $options + * @param array $params + */ +function financialacls_civicrm_fieldOptions($entity, $field, &$options, $params) { + if ($entity === 'Contribution' && $field === 'financial_type_id' && $params['context'] === 'search') { + $action = CRM_Core_Action::VIEW; + // At this stage we are only considering the view action. Code from + // CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes(). + $actions = [ + CRM_Core_Action::VIEW => 'view', + CRM_Core_Action::UPDATE => 'edit', + CRM_Core_Action::ADD => 'add', + CRM_Core_Action::DELETE => 'delete', + ]; + $cacheKey = 'available_types_' . $action; + if (!isset(\Civi::$statics['CRM_Financial_BAO_FinancialType'][$cacheKey])) { + foreach ($options as $finTypeId => $type) { + if (!CRM_Core_Permission::check($actions[$action] . ' contributions of type ' . $type)) { + unset($options[$finTypeId]); + } + } + \Civi::$statics['CRM_Financial_BAO_FinancialType'][$cacheKey] = $options; + } + $options = \Civi::$statics['CRM_Financial_BAO_FinancialType'][$cacheKey]; + } +} + // --- Functions below this ship commented out. Uncomment as required. --- /**