AddHoneyPotFieldToDonationForms.php
1 year ago
ConvertConsentBlockToFieldsApi.php
2 years ago
ConvertDonationAmountBlockToFieldsApi.php
2 years ago
ConvertDonationFormBlocksToFieldsApi.php
1 year ago
ConvertQueryDataToDonationForm.php
2 years ago
DispatchDonateControllerDonationCreatedListeners.php
1 year ago
DispatchDonateControllerSubscriptionCreatedListeners.php
2 years ago
GenerateAuthUrl.php
2 years ago
GenerateDonateRouteSignatureArgs.php
2 years ago
GenerateDonateRouteUrl.php
2 years ago
GenerateDonationConfirmationReceiptUrl.php
2 years ago
GenerateDonationConfirmationReceiptViewRouteUrl.php
2 years ago
GenerateDonationFormPreviewRouteUrl.php
2 years ago
GenerateDonationFormValidationRouteUrl.php
2 years ago
GenerateDonationFormViewRouteUrl.php
2 years ago
GetOrCreateDonor.php
2 years ago
PrintFormMetaTags.php
1 year ago
ReplaceGiveReceiptShortcodeViewWithDonationConfirmationIframe.php
1 year ago
SanitizeDonationFormPreviewRequest.php
2 years ago
StoreBackwardsCompatibleFormMeta.php
2 years ago
ConvertConsentBlockToFieldsApi.php
61 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\DonationForms\Actions; |
| 4 | |
| 5 | use Give\Framework\Blocks\BlockModel; |
| 6 | use Give\Framework\FieldsAPI\Consent; |
| 7 | |
| 8 | class ConvertConsentBlockToFieldsApi |
| 9 | { |
| 10 | /** |
| 11 | * @since 3.0.0 |
| 12 | */ |
| 13 | public function __invoke(BlockModel $block, int $blockIndex) |
| 14 | { |
| 15 | return Consent::make('consent' . '-' . $blockIndex) |
| 16 | ->tap(function (Consent $consentField) use ($block) { |
| 17 | if ($block->getAttribute('useGlobalSettings')) { |
| 18 | $this->setGlobalAttributes($consentField); |
| 19 | } else { |
| 20 | $this->setPerFormAttributes($consentField, $block); |
| 21 | } |
| 22 | |
| 23 | return $consentField; |
| 24 | }); |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * @since 3.0.0 |
| 29 | * |
| 30 | * @return void |
| 31 | */ |
| 32 | private function setGlobalAttributes(Consent $field) |
| 33 | { |
| 34 | $field |
| 35 | ->useGlobalSettings(true) |
| 36 | ->checkboxLabel(give_get_option('agree_to_terms_label')) |
| 37 | ->displayType('showFormTerms') |
| 38 | ->linkText(__('Show terms', 'give')) |
| 39 | ->agreementText(give_get_option('agreement_text')); |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * @since 3.0.0 |
| 44 | * |
| 45 | * @return void |
| 46 | */ |
| 47 | private function setPerFormAttributes(Consent $field, BlockModel $block) |
| 48 | { |
| 49 | $field |
| 50 | ->useGlobalSettings(false) |
| 51 | ->checkboxLabel($block->getAttribute('checkboxLabel')) |
| 52 | ->displayType($block->getAttribute('displayType')) |
| 53 | ->linkText($block->getAttribute('linkText')) |
| 54 | ->linkUrl($block->getAttribute('linkUrl')) |
| 55 | ->modalHeading($block->getAttribute('modalHeading')) |
| 56 | ->modalAcceptanceText($block->getAttribute('modalAcceptanceText')) |
| 57 | ->agreementText($block->getAttribute('agreementText')); |
| 58 | } |
| 59 | |
| 60 | } |
| 61 |