| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentForm\App\Modules\Payments\Components; |
| 4 |
|
| 5 |
if (!defined('ABSPATH')) { |
| 6 |
exit; // Exit if accessed directly. |
| 7 |
} |
| 8 |
|
| 9 |
use FluentForm\App\Services\FormBuilder\BaseFieldManager; |
| 10 |
use FluentForm\App\Services\FormBuilder\Components\CustomHtml; |
| 11 |
use FluentForm\App\Services\FormBuilder\Components\Text; |
| 12 |
|
| 13 |
class PaymentSummaryComponent extends BaseFieldManager |
| 14 |
{ |
| 15 |
public function __construct( |
| 16 |
$key = 'payment_summary_component', |
| 17 |
$title = 'Payment Summary', |
| 18 |
$tags = ['payment', 'summary', 'cart'], |
| 19 |
$position = 'payments' |
| 20 |
) |
| 21 |
{ |
| 22 |
parent::__construct( |
| 23 |
$key, |
| 24 |
$title, |
| 25 |
$tags, |
| 26 |
$position |
| 27 |
); |
| 28 |
} |
| 29 |
|
| 30 |
|
| 31 |
public function register() |
| 32 |
{ |
| 33 |
add_filter('fluentform/editor_components', array($this, 'pushComponent')); |
| 34 |
add_filter('fluentform/editor_element_settings_placement', array($this, 'pushEditorElementPositions')); |
| 35 |
add_filter('fluentform/editor_element_search_tags', array($this, 'pushTags'), 10, 2); |
| 36 |
add_action('fluentform/render_item_' . $this->key, array($this, 'render'), 10, 2); |
| 37 |
|
| 38 |
add_filter('fluentform/editor_element_customization_settings', function ($settings) { |
| 39 |
if ($customSettings = $this->getEditorCustomizationSettings()) { |
| 40 |
$settings = array_merge($settings, $customSettings); |
| 41 |
} |
| 42 |
|
| 43 |
return $settings; |
| 44 |
}); |
| 45 |
|
| 46 |
add_filter('fluentform/editor_init_element_payment_summary_component', function ($item) { |
| 47 |
if (!isset($item['settings']['show_close_button'])) { |
| 48 |
$item['settings']['show_close_button'] = false; |
| 49 |
} |
| 50 |
return $item; |
| 51 |
}); |
| 52 |
|
| 53 |
|
| 54 |
// add_filter('fluentform/supported_conditional_fields', array($this, 'pushConditionalSupport')); |
| 55 |
|
| 56 |
} |
| 57 |
|
| 58 |
function getComponent() |
| 59 |
{ |
| 60 |
return array( |
| 61 |
'index' => 7, |
| 62 |
'element' => $this->key, |
| 63 |
'attributes' => array(), |
| 64 |
'settings' => array( |
| 65 |
'html_codes' => '<p>' . __('Payment Summary will be shown here', 'fluentform') . '</p>', |
| 66 |
'cart_empty_text' => __('No payment items has been selected yet', 'fluentform'), |
| 67 |
'show_close_button' => false, |
| 68 |
'conditional_logics' => array(), |
| 69 |
'container_class' => '' |
| 70 |
), |
| 71 |
'editor_options' => array( |
| 72 |
'title' => __('Payment Summary', 'fluentform'), |
| 73 |
'icon_class' => 'ff-edit-html', |
| 74 |
'template' => 'customHTML' |
| 75 |
), |
| 76 |
); |
| 77 |
} |
| 78 |
|
| 79 |
public function getGeneralEditorElements() |
| 80 |
{ |
| 81 |
return [ |
| 82 |
'cart_empty_text', |
| 83 |
'show_close_button' |
| 84 |
]; |
| 85 |
} |
| 86 |
|
| 87 |
public function generalEditorElement() |
| 88 |
{ |
| 89 |
return [ |
| 90 |
'cart_empty_text' => [ |
| 91 |
'template' => 'inputHTML', |
| 92 |
'label' => __('Empty Payment Selected Text', 'fluentform'), |
| 93 |
'help_text' => __('The provided text will show if no payment item is selected yet', 'fluentform'), |
| 94 |
'hide_extra' => 'yes' |
| 95 |
], |
| 96 |
'show_close_button' => [ |
| 97 |
'template' => 'inputCheckbox', |
| 98 |
'options' => [ |
| 99 |
[ |
| 100 |
'value' => false, |
| 101 |
'label' => __('Show close button for closing Payment Summary', 'fluentform'), |
| 102 |
], |
| 103 |
] |
| 104 |
] |
| 105 |
]; |
| 106 |
} |
| 107 |
|
| 108 |
public function getAdvancedEditorElements() |
| 109 |
{ |
| 110 |
return [ |
| 111 |
'conditional_logics', |
| 112 |
'container_class' |
| 113 |
]; |
| 114 |
} |
| 115 |
|
| 116 |
function render($data, $form) |
| 117 |
{ |
| 118 |
$fallBack = $data['settings']['cart_empty_text']; |
| 119 |
$data['settings']['html_codes'] = '<div class="ff_dynamic_value ff_dynamic_payment_summary" data-ref="payment_summary"><div class="ff_payment_summary"></div><div class="ff_payment_summary_fallback">'.$fallBack.'</div></div>'; |
| 120 |
|
| 121 |
add_filter('fluentform/payment_config', function($config, $formId) use ($data) { |
| 122 |
$name = $data['attributes']['name']; |
| 123 |
|
| 124 |
$config['payment_summary_config'][$name] = [ |
| 125 |
'show_close_button' => !empty($data['settings']['show_close_button']) |
| 126 |
]; |
| 127 |
|
| 128 |
return $config; |
| 129 |
}, 10, 2); |
| 130 |
|
| 131 |
return (new CustomHtml())->compile($data, $form); |
| 132 |
} |
| 133 |
} |
| 134 |
|