Merge pull request #22805 from braders/permission_denied_wordpress_improvement-altern...
[civicrm-core.git] / CRM / Contribute / Form / Task.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
bc77d7c0 4 | Copyright CiviCRM LLC. All rights reserved. |
6a488035 5 | |
bc77d7c0
TO
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
6a488035 9 +--------------------------------------------------------------------+
d25dd0ee 10 */
6a488035
TO
11
12/**
13 *
14 * @package CRM
ca5cec67 15 * @copyright CiviCRM LLC https://civicrm.org/licensing
6a488035
TO
16 */
17
18/**
31aaf096
MW
19 * Class for contribute form task actions.
20 * FIXME: This needs refactoring to properly inherit from CRM_Core_Form_Task and share more functions.
6a488035 21 */
31aaf096 22class CRM_Contribute_Form_Task extends CRM_Core_Form_Task {
6a488035 23
5b43eb5a 24 use CRM_Contribute_Form_Task_TaskTrait;
25
6a488035 26 /**
fe482240 27 * The array that holds all the contribution ids.
6a488035
TO
28 *
29 * @var array
30 */
31 protected $_contributionIds;
32
6a488035 33 /**
fe482240 34 * Build all the data structures needed to build the form.
6a488035 35 */
00be9182 36 public function preProcess() {
6a488035
TO
37 self::preProcessCommon($this);
38 }
39
186c9c17 40 /**
46c4230d 41 * @param \CRM_Contribute_Form_Task $form
2d09a0c3 42 *
43 * @throws \CRM_Core_Exception
186c9c17 44 */
46c4230d 45 public static function preProcessCommon(&$form): void {
be2fb01f 46 $form->_contributionIds = [];
6a488035 47
2d09a0c3 48 $values = $form->getSearchFormValues();
6a488035 49
9c1bc317 50 $form->_task = $values['task'] ?? NULL;
6a488035 51
06dec048 52 $ids = $form->getIDs();
53 $form->_componentClause = $form->getComponentClause();
54 $form->assign('totalSelectedContributions', count($ids));
6a488035 55 $form->_contributionIds = $form->_componentIds = $ids;
7f20f38e 56 $form->set('contributionIds', $form->_contributionIds);
faa31fa6 57 $form->setNextUrl('contribute');
6a488035
TO
58 }
59
59d861cb 60 /**
61 * Sets contribution Ids for unit test.
bc854509 62 *
63 * @param array $contributionIds
59d861cb 64 */
9da59513 65 public function setContributionIds(array $contributionIds): void {
66 $this->ids = $contributionIds;
59d861cb 67 }
68
6a488035
TO
69 /**
70 * Given the contribution id, compute the contact id
71 * since its used for things like send email
72 */
419b3ce9 73 public function setContactIDs(): void {
102279e2 74 if (!$this->isQueryIncludesSoftCredits()) {
797ddfb4 75 $this->_contactIds = CRM_Core_DAO::getContactIDsFromComponent(
34eec215
DS
76 $this->_contributionIds,
77 'civicrm_contribution'
78 );
79 }
6a488035
TO
80 }
81
82 /**
100fef9d 83 * Simple shell that derived classes can call to add buttons to
6a488035
TO
84 * the form with a customized title for the main Submit
85 *
014c4014
TO
86 * @param string $title
87 * Title of the main button.
88 * @param string $nextType
89 * Button type for the form after processing.
da6b46f4
EM
90 * @param string $backType
91 * @param bool $submitOnce
6a488035 92 */
00be9182 93 public function addDefaultButtons($title, $nextType = 'next', $backType = 'back', $submitOnce = FALSE) {
be2fb01f 94 $this->addButtons([
1330f57a
SL
95 [
96 'type' => $nextType,
97 'name' => $title,
98 'isDefault' => TRUE,
99 ],
100 [
101 'type' => $backType,
102 'name' => ts('Cancel'),
103 ],
104 ]);
6a488035 105 }
96025800 106
601c941f
EM
107 /**
108 * Get the token processor schema required to list any tokens for this task.
109 *
110 * @return array
111 */
112 public function getTokenSchema(): array {
113 return ['contributionId', 'contactId'];
114 }
115
6a488035 116}