|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Adyen Payment Module |
| 4 | + * |
| 5 | + * Copyright (c) 2023 Adyen N.V. |
| 6 | + * This file is open source and available under the MIT license. |
| 7 | + * See the LICENSE file for more info. |
| 8 | + * |
| 9 | + * Author: Adyen <[email protected]> |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Adyen\Payment\Block\Adminhtml\Support; |
| 13 | + |
| 14 | +use Adyen\Payment\Helper\SupportFormHelper; |
| 15 | +use Magento\Backend\Block\Template\Context; |
| 16 | +use Magento\Backend\Block\Widget\Form\Generic; |
| 17 | +use Magento\Framework\Data\FormFactory; |
| 18 | +use Magento\Framework\Exception\LocalizedException; |
| 19 | +use Magento\Framework\Registry; |
| 20 | + |
| 21 | +class ConfigurationSettingsForm extends Generic |
| 22 | +{ |
| 23 | + /** |
| 24 | + * @var SupportFormHelper |
| 25 | + */ |
| 26 | + private $supportFormHelper; |
| 27 | + |
| 28 | + /** |
| 29 | + * @param Context $context |
| 30 | + * @param Registry $registry |
| 31 | + * @param FormFactory $formFactory |
| 32 | + * @param SupportFormHelper $supportFormHelper |
| 33 | + */ |
| 34 | + public function __construct( |
| 35 | + Context $context, |
| 36 | + Registry $registry, |
| 37 | + FormFactory $formFactory, |
| 38 | + SupportFormHelper $supportFormHelper |
| 39 | + ) { |
| 40 | + $this->supportFormHelper = $supportFormHelper; |
| 41 | + parent::__construct($context, $registry, $formFactory); |
| 42 | + $this->setActive(true); |
| 43 | + } |
| 44 | + |
| 45 | + /** |
| 46 | + * Prepare form before rendering HTML |
| 47 | + * |
| 48 | + * @return $this |
| 49 | + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) |
| 50 | + * @throws LocalizedException |
| 51 | + */ |
| 52 | + protected function _prepareForm(): ConfigurationSettingsForm |
| 53 | + { |
| 54 | + $form = $this->_formFactory->create([ |
| 55 | + 'data' => [ |
| 56 | + 'id' => 'support_form', |
| 57 | + 'action' => $this->getUrl('adyen/support/configurationsettingsform'), |
| 58 | + 'method' => 'post', |
| 59 | + 'enctype' => 'multipart/form-data', |
| 60 | + ] |
| 61 | + ]); |
| 62 | + |
| 63 | + $fieldset = $form->addFieldset('base_fieldset', ['legend' => __('Configuration settings')]); |
| 64 | + $this->_addElementTypes($fieldset); |
| 65 | + |
| 66 | + $fieldset->addType( |
| 67 | + 'textarea', |
| 68 | + 'Adyen\Payment\Block\Adminhtml\Support\Form\Element\CustomTextareaElement' |
| 69 | + ); |
| 70 | + |
| 71 | + $fieldset->addField( |
| 72 | + 'topic', |
| 73 | + 'select', |
| 74 | + [ |
| 75 | + 'name' => 'topic', |
| 76 | + 'label' => __('Topic'), |
| 77 | + 'title' => __('Topic'), |
| 78 | + 'class' => '', |
| 79 | + 'options' => $this->getSupportTopics(), |
| 80 | + 'required' => true, |
| 81 | + 'value' => $this->getRequest()->getParam('topic'), |
| 82 | + ] |
| 83 | + ); |
| 84 | + $fieldset->addField( |
| 85 | + 'issue', |
| 86 | + 'select', |
| 87 | + [ |
| 88 | + 'name' => 'issue', |
| 89 | + 'label' => __('Issue'), |
| 90 | + 'title' => __('Issue'), |
| 91 | + 'class' => '', |
| 92 | + 'options' => $this->getIssuesTopics(), |
| 93 | + 'required' => true |
| 94 | + ] |
| 95 | + ); |
| 96 | + $fieldset->addField( |
| 97 | + 'subject', |
| 98 | + 'text', |
| 99 | + [ |
| 100 | + 'name' => 'subject', |
| 101 | + 'label' => __('Subject'), |
| 102 | + 'title' => __('Subject'), |
| 103 | + 'placeholder' => __('Type a subject for your issue'), |
| 104 | + 'class' => 'adyen_support-form', |
| 105 | + 'required' => true |
| 106 | + ] |
| 107 | + ); |
| 108 | + |
| 109 | + $fieldset->addField( |
| 110 | + 'email', |
| 111 | + 'text', |
| 112 | + [ |
| 113 | + 'name' => 'email', |
| 114 | + 'label' => __('Email'), |
| 115 | + 'title' => __('Email'), |
| 116 | + 'class' => 'validate-emails', |
| 117 | + 'required' => true, |
| 118 | + 'readonly' => true, |
| 119 | + 'value' => $this->supportFormHelper->getAdminEmail(), |
| 120 | + ] |
| 121 | + ); |
| 122 | + |
| 123 | + $fieldset->addField( |
| 124 | + 'headless', |
| 125 | + 'radios', |
| 126 | + [ |
| 127 | + 'name' => 'headless', |
| 128 | + 'label' => __('Are you using headless integration?'), |
| 129 | + 'title' => __('Are you using headless integration?'), |
| 130 | + 'class' => '', |
| 131 | + 'required' => false, 'values' => [ |
| 132 | + ['value' => 'Yes', 'label' => __('Yes')], |
| 133 | + ['value' => 'No', 'label' => __('No')]], |
| 134 | + 'value' => 'No' |
| 135 | + ] |
| 136 | + )->setAfterElementHtml(' |
| 137 | + <div class="tooltip"> |
| 138 | + <span class="help"> |
| 139 | + <span></span> |
| 140 | + </span> |
| 141 | + <div class="tooltip-content"> |
| 142 | + Headless integration is when you use Adyen pre-configured backend but have a custom store frontend. |
| 143 | + </div> |
| 144 | + </div>'); |
| 145 | + |
| 146 | + $fieldset->addType('file', 'Adyen\Payment\Block\Adminhtml\Support\Form\Element\MultipleFileElement'); |
| 147 | + $fieldset->addField( |
| 148 | + 'attachments', |
| 149 | + 'file', |
| 150 | + [ |
| 151 | + 'name' => 'attachments[]', |
| 152 | + 'multiple' => 'multiple', |
| 153 | + 'label' => __('Relevant logs & screenshots'), |
| 154 | + 'title' => __('Relevant logs & screenshots'), |
| 155 | + 'class' => 'adyen_support-form', |
| 156 | + 'required' => false |
| 157 | + ] |
| 158 | + )->setAfterElementHtml(' |
| 159 | + <div class="tooltip"> |
| 160 | + <span class="help"> |
| 161 | + <span></span> |
| 162 | + </span> |
| 163 | + <div class="tooltip-content">Sending us a file often helps us to solve your issue. |
| 164 | + We accept files in PNG, JPG, ZIP, RAR, or SVG format, with a maximum size of 10 MB. |
| 165 | + </div> |
| 166 | + </div>'); |
| 167 | + |
| 168 | + $fieldset->addField( |
| 169 | + 'sendConfigurationValues', |
| 170 | + 'radios', |
| 171 | + [ |
| 172 | + 'name' => 'sendConfigurationValues', |
| 173 | + 'label' => __('Do you want to include plugin configuration values?'), |
| 174 | + 'title' => __('Do you want to include plugin configuration values?'), |
| 175 | + 'class' => '', |
| 176 | + 'required' => false, |
| 177 | + 'values' => [ |
| 178 | + ['value' => 1, 'label' => __('Yes')], |
| 179 | + ['value' => 0, 'label' => __('No')] |
| 180 | + ], |
| 181 | + 'value' => 1 |
| 182 | + ] |
| 183 | + )->setAfterElementHtml(' |
| 184 | + <div class="tooltip"> |
| 185 | + <span class="help"> |
| 186 | + <span></span> |
| 187 | + </span> |
| 188 | + <div class="tooltip-content">Automatically includes the configuration values in support email. |
| 189 | + </div> |
| 190 | + </div>'); |
| 191 | + |
| 192 | + $fieldset->addField( |
| 193 | + 'description', |
| 194 | + 'textarea', |
| 195 | + [ |
| 196 | + 'name' => 'descriptionComments', |
| 197 | + 'label' => __('Description'), |
| 198 | + 'title' => __('Description'), |
| 199 | + 'placeholder' => __('Tell us what is happening in detail'), |
| 200 | + 'class' => '', |
| 201 | + 'required' => false, |
| 202 | + ] |
| 203 | + ); |
| 204 | + |
| 205 | + $fieldset->addField( |
| 206 | + 'submit_support_configuration_settings', |
| 207 | + 'submit', |
| 208 | + [ |
| 209 | + 'name' => 'submit', |
| 210 | + 'title' => __('Submit'), |
| 211 | + 'class' => 'primary', |
| 212 | + 'value' => 'Submit' |
| 213 | + ] |
| 214 | + ); |
| 215 | + |
| 216 | + $form->setUseContainer(true); |
| 217 | + |
| 218 | + $this->setForm($form); |
| 219 | + return parent::_prepareForm(); |
| 220 | + } |
| 221 | + |
| 222 | + /** |
| 223 | + * @return string[] |
| 224 | + */ |
| 225 | + public function getSupportTopics(): array |
| 226 | + { |
| 227 | + return $this->supportFormHelper->getSupportTopicsByFormType( |
| 228 | + SupportFormHelper::CONFIGURATION_SETTINGS_FORM |
| 229 | + ); |
| 230 | + } |
| 231 | + |
| 232 | + /** |
| 233 | + * @return string[] |
| 234 | + */ |
| 235 | + public function getIssuesTopics(): array |
| 236 | + { |
| 237 | + return $this->supportFormHelper->getIssuesTopicsByFormType( |
| 238 | + SupportFormHelper::CONFIGURATION_SETTINGS_FORM |
| 239 | + ); |
| 240 | + } |
| 241 | +} |
0 commit comments