Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(REF) dev/core#2571 - Add helper functions for reCAPTCHA extension #20315

Merged
merged 1 commit into from
Jul 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions CRM/Campaign/Form/Petition/Signature.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,27 @@ public function getContactID() {
return $session->get('userID');
}

/**
* Get the active UFGroups (profiles) on this form
* Many forms load one or more UFGroups (profiles).
* This provides a standard function to retrieve the IDs of those profiles from the form
* so that you can implement things such as "is is_captcha field set on any of the active profiles on this form?"
*
* NOT SUPPORTED FOR USE OUTSIDE CORE EXTENSIONS - Added for reCAPTCHA core extension.
*
* @return array
*/
public function getUFGroupIDs() {
$ufGroupIDs = [];
if (!empty($this->_contactProfileId)) {
$ufGroupIDs[] = $this->_contactProfileId;
}
if (!empty($this->_activityProfileId)) {
$ufGroupIDs[] = $this->_activityProfileId;
}
return $ufGroupIDs;
}

public function preProcess() {
$this->bao = new CRM_Campaign_BAO_Petition();
$this->_mode = self::MODE_CREATE;
Expand Down
29 changes: 29 additions & 0 deletions CRM/Contribute/Form/Contribution/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,35 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu
protected $_paymentProcessorID;
protected $_snippet;

/**
* Get the active UFGroups (profiles) on this form
* Many forms load one or more UFGroups (profiles).
* This provides a standard function to retrieve the IDs of those profiles from the form
* so that you can implement things such as "is is_captcha field set on any of the active profiles on this form?"
*
* NOT SUPPORTED FOR USE OUTSIDE CORE EXTENSIONS - Added for reCAPTCHA core extension.
*
* @return array
*/
public function getUFGroupIDs() {
$ufGroupIDs = [];
if (!empty($this->_values['custom_pre_id'])) {
$ufGroupIDs[] = $this->_values['custom_pre_id'];
}
if (!empty($this->_values['custom_post_id'])) {
// custom_post_id can be an array (because we can have multiple for events).
// It is handled as array for contribution page as well though they don't support multiple profiles.
if (!is_array($this->_values['custom_post_id'])) {
$ufGroupIDs[] = $this->_values['custom_post_id'];
}
else {
$ufGroupIDs = array_merge($ufGroupIDs, $this->_values['custom_post_id']);
}
}

return $ufGroupIDs;
}

/**
* Set variables up before form is built.
*/
Expand Down
7 changes: 0 additions & 7 deletions CRM/Contribute/Form/ContributionBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -820,13 +820,6 @@ public function assignPaymentFields() {
}
}

/**
* Check if ReCAPTCHA has to be added on Contribution form forcefully.
*/
protected function hasToAddForcefully() {
return CRM_Utils_ReCAPTCHA::hasToAddForcefully();
}

/**
* Add onbehalf/honoree profile fields and native module fields.
*
Expand Down
14 changes: 14 additions & 0 deletions CRM/Core/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -2751,4 +2751,18 @@ protected function getSubmittedValue(string $fieldName) {
return $this->exportedValues[$fieldName] ?? NULL;
}

/**
* Get the active UFGroups (profiles) on this form
* Many forms load one or more UFGroups (profiles).
* This provides a standard function to retrieve the IDs of those profiles from the form
* so that you can implement things such as "is is_captcha field set on any of the active profiles on this form?"
*
* NOT SUPPORTED FOR USE OUTSIDE CORE EXTENSIONS - Added for reCAPTCHA core extension.
*
* @return array
*/
public function getUFGroupIDs() {
return [];
}

}
20 changes: 20 additions & 0 deletions CRM/Event/Form/Registration/AdditionalParticipant.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,26 @@ class CRM_Event_Form_Registration_AdditionalParticipant extends CRM_Event_Form_R
*/
public $additionalParticipantId = NULL;

/**
* Get the active UFGroups (profiles) on this form
* Many forms load one or more UFGroups (profiles).
* This provides a standard function to retrieve the IDs of those profiles from the form
* so that you can implement things such as "is is_captcha field set on any of the active profiles on this form?"
*
* NOT SUPPORTED FOR USE OUTSIDE CORE EXTENSIONS - Added for reCAPTCHA core extension.
*
* @return array
*/
public function getUFGroupIDs() {
$ufGroupIDs = [];
foreach (['pre', 'post'] as $keys) {
if (isset($this->_values['additional_custom_' . $keys . '_id'])) {
$ufGroupIDs[] = $this->_values['additional_custom_' . $keys . '_id'];
}
}
return $ufGroupIDs;
}

/**
* Set variables up before form is built.
*
Expand Down
28 changes: 28 additions & 0 deletions CRM/Event/Form/Registration/Register.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,34 @@ public static function getRegistrationContactID($fields, $form, $isAdditional) {
return $contactID;
}

/**
* Get the active UFGroups (profiles) on this form
* Many forms load one or more UFGroups (profiles).
* This provides a standard function to retrieve the IDs of those profiles from the form
* so that you can implement things such as "is is_captcha field set on any of the active profiles on this form?"
*
* NOT SUPPORTED FOR USE OUTSIDE CORE EXTENSIONS - Added for reCAPTCHA core extension.
*
* @return array
*/
public function getUFGroupIDs() {
$ufGroupIDs = [];
if (!empty($this->_values['custom_pre_id'])) {
$ufGroupIDs[] = $this->_values['custom_pre_id'];
}
if (!empty($this->_values['custom_post_id'])) {
// custom_post_id can be an array (because we can have multiple for events).
// It is handled as array for contribution page as well though they don't support multiple profiles.
if (!is_array($this->_values['custom_post_id'])) {
$ufGroupIDs[] = $this->_values['custom_post_id'];
}
else {
$ufGroupIDs = array_merge($ufGroupIDs, $this->_values['custom_post_id']);
}
}
return $ufGroupIDs;
}

/**
* Set variables up before form is built.
*
Expand Down
30 changes: 24 additions & 6 deletions CRM/PCP/Form/PCPAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,24 @@ class CRM_PCP_Form_PCPAccount extends CRM_Core_Form {
*/
public $_single;

/**
* Get the active UFGroups (profiles) on this form
* Many forms load one or more UFGroups (profiles).
* This provides a standard function to retrieve the IDs of those profiles from the form
* so that you can implement things such as "is is_captcha field set on any of the active profiles on this form?"
*
* NOT SUPPORTED FOR USE OUTSIDE CORE EXTENSIONS - Added for reCAPTCHA core extension.
*
* @return array
*/
public function getUFGroupIDs() {
$ufGroupIDs = [];
if (!empty($this->_pageId)) {
$ufGroupIDs[] = CRM_PCP_BAO_PCP::getSupporterProfileId($this->_pageId, $this->_component);
}
return $ufGroupIDs;
}

public function preProcess() {
$session = CRM_Core_Session::singleton();
$config = CRM_Core_Config::singleton();
Expand Down Expand Up @@ -117,21 +135,21 @@ public function setDefaultValues() {
* @return void
*/
public function buildQuickForm() {
$id = CRM_PCP_BAO_PCP::getSupporterProfileId($this->_pageId, $this->_component);
if (CRM_PCP_BAO_PCP::checkEmailProfile($id)) {
$ufGroupID = CRM_PCP_BAO_PCP::getSupporterProfileId($this->_pageId, $this->_component);
if (CRM_PCP_BAO_PCP::checkEmailProfile($ufGroupID)) {
$this->assign('profileDisplay', TRUE);
}
$fields = NULL;
if ($this->_contactID) {
if (CRM_Core_BAO_UFGroup::filterUFGroups($id, $this->_contactID)) {
$fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD);
if (CRM_Core_BAO_UFGroup::filterUFGroups($ufGroupID, $this->_contactID)) {
$fields = CRM_Core_BAO_UFGroup::getFields($ufGroupID, FALSE, CRM_Core_Action::ADD);
}
$this->addFormRule(['CRM_PCP_Form_PCPAccount', 'formRule'], $this);
}
else {
CRM_Core_BAO_CMSUser::buildForm($this, $id, TRUE);
CRM_Core_BAO_CMSUser::buildForm($this, $ufGroupID, TRUE);

$fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD);
$fields = CRM_Core_BAO_UFGroup::getFields($ufGroupID, FALSE, CRM_Core_Action::ADD);
}

if ($fields) {
Expand Down
28 changes: 28 additions & 0 deletions CRM/Profile/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,34 @@ public function getDefaultEntity() {
return 'Profile';
}

/**
* Get the active UFGroups (profiles) on this form
* Many forms load one or more UFGroups (profiles).
* This provides a standard function to retrieve the IDs of those profiles from the form
* so that you can implement things such as "is is_captcha field set on any of the active profiles on this form?"
*
* NOT SUPPORTED FOR USE OUTSIDE CORE EXTENSIONS - Added for reCAPTCHA core extension.
*
* @return array
*/
public function getUFGroupIDs() {
if (empty($this->_profileIds)) {
$dao = new CRM_Core_DAO_UFGroup();
$dao->id = $this->_gid;
$this->_profileIds = (array) $dao;
}
return $this->_profileIds;
}

/**
* Are we using the profile in create mode?
*
* @return bool
*/
public function getIsCreateMode() {
return ($this->_mode == self::MODE_CREATE);
}

/**
* Pre processing work done here.
*
Expand Down