DesignHeaderSettings.php
2 years ago
DonationSummarySettings.php
2 years ago
FormMigrationPayload.php
2 years ago
TransferOptions.php
2 years ago
DonationSummarySettings.php
63 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\FormMigration\DataTransferObjects; |
| 4 | |
| 5 | /** |
| 6 | * The `Sequoia` and `Classic` templates share a structure for Donation Summary settings. |
| 7 | * |
| 8 | * @since 3.0.0 |
| 9 | */ |
| 10 | class DonationSummarySettings |
| 11 | { |
| 12 | /** @var bool */ |
| 13 | protected $enabled; |
| 14 | |
| 15 | /** @var string */ |
| 16 | protected $heading; |
| 17 | |
| 18 | /** @var string */ |
| 19 | protected $location; |
| 20 | |
| 21 | /** |
| 22 | * @param string $enabled `donation_summary_enabled` A string value of `enabled` or `disabled`. |
| 23 | * @param string $heading `donation_summary_heading` ie 'Here\'s what you\'re about to donate:' |
| 24 | * @param string $location `donation_summary_location` A string representing a corresponding template hook. |
| 25 | */ |
| 26 | public function __construct($enabled, $heading, $location) |
| 27 | { |
| 28 | $this->enabled = give_is_setting_enabled($enabled); |
| 29 | $this->heading = $heading; |
| 30 | $this->location = $location; |
| 31 | } |
| 32 | |
| 33 | public static function make($settings) |
| 34 | { |
| 35 | return new self( |
| 36 | $settings['donation_summary_enabled'], |
| 37 | $settings['donation_summary_enabled'], |
| 38 | $settings['donation_summary_location'] |
| 39 | ); |
| 40 | } |
| 41 | |
| 42 | public function getHeading(): string |
| 43 | { |
| 44 | return $this->heading ?: __('Donation Summary', 'give'); |
| 45 | } |
| 46 | |
| 47 | public function isEnabled(): bool |
| 48 | { |
| 49 | return $this->enabled; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * @since 3.0.0 |
| 54 | * |
| 55 | * @note `give_donation_form_user_info` is presented as "Before payment fields". |
| 56 | * @note `give_donation_form_before_submit` is the default location, presented as "After payment fields". |
| 57 | */ |
| 58 | public function isBeforePaymentFields(): bool |
| 59 | { |
| 60 | return 'give_donation_form_user_info' === $this->location; |
| 61 | } |
| 62 | } |
| 63 |