| 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 |
|