Completed
Branch FET/paypal-smart-button2 (052e8d)
by
unknown
102:07 queued 88:11
created

PrivacySettingsFormHandler::generate()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 52
Code Lines 32

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 32
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 52
rs 9.4929

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace EventEspresso\core\domain\services\admin\privacy\forms;
4
5
use EE_Config;
6
use EE_Form_Section_HTML;
7
use EE_Form_Section_Proper;
8
use EE_Full_HTML_Validation_Strategy;
9
use EE_Registration_Config;
10
use EE_Registry;
11
use EE_Select_Reveal_Input;
12
use EE_Text_Area_Input;
13
use EEH_HTML;
14
use EventEspresso\core\exceptions\InvalidFormSubmissionException;
15
use EventEspresso\core\libraries\form_sections\form_handlers\FormHandler;
16
use EventEspresso\core\services\loaders\LoaderFactory;
17
18
/**
19
 * Class PrivacySettingsFormHandler
20
 *
21
 * Class for displaying and processing the privacy settings form
22
 *
23
 * @package        Event Espresso
24
 * @author         Mike Nelson
25
 * @since          $VID:$
26
 *
27
 */
28
class PrivacySettingsFormHandler extends FormHandler
29
{
30
31
    /**
32
     * @var EE_Config
33
     */
34
    protected $config;
35
36
37
    /**
38
     * PrivacySettingsFormHandler constructor.
39
     *
40
     * @param EE_Registry $registry
41
     * @param EE_Config   $config
42
     */
43
    public function __construct(EE_Registry $registry, EE_Config $config)
44
    {
45
        $this->config = $config;
46
        parent::__construct(
47
            esc_html__('Privacy Settings', 'event_espresso'),
48
            esc_html__('Privacy Settings', 'event_espresso'),
49
            'privacy-settings',
50
            '',
51
            FormHandler::DO_NOT_SETUP_FORM,
52
            $registry
53
        );
54
    }
55
56
57
    /**
58
     * creates and returns the actual form
59
     *
60
     * @return EE_Form_Section_Proper
61
     */
62
    public function generate()
63
    {
64
        // this form makes use of the session for passing around invalid form submission data, so make sure its enabled
65
        add_filter('FHEE__EE_Session___save_session_to_db__abort_session_save', '__return_false');
66
        /**
67
         * @var $reg_config EE_Registration_Config
68
         */
69
        $reg_config = $this->config->registration;
70
        return new EE_Form_Section_Proper(
71
            array(
72
                'name'        => 'privacy_consent_settings',
73
                'subsections' => array(
74
                    'privacy_consent_form_hdr' => new EE_Form_Section_HTML(
75
                        EEH_HTML::h2(esc_html__('Privacy Policy Consent Settings', 'event_espresso'))
76
                    ),
77
                    'enable'                   => new EE_Select_Reveal_Input(
78
                        array(
79
                            'enable-privacy-consent' => esc_html__('Enabled', 'event_espresso'),
80
                            'disable'                => esc_html__('Disabled', 'event_espresso'),
81
                        ),
82
                        array(
83
                            'default'         => $reg_config->isConsentCheckboxEnabled()
84
                                ? 'enable-privacy-consent'
85
                                : 'disable',
86
                            'html_label_text' => esc_html__('Privacy Consent Checkbox', 'event_espresso'),
87
                            'html_help_text'  => esc_html__(
88
                                'When enabled, a checkbox appears in the registration form requiring users to consent to your site\'s privacy policy.',
89
                                'event_espresso'
90
                            ),
91
                        )
92
                    ),
93
                    'enable-privacy-consent'   => new EE_Form_Section_Proper(
94
                        array(
95
                            'subsections' => array(
96
                                'consent_assertion' => new EE_Text_Area_Input(
97
                                    array(
98
                                        'default'               => $reg_config->getConsentCheckboxLabelText(),
99
                                        'html_label_text'       => esc_html__('Consent Text', 'event_espresso'),
100
                                        'html_help_text'        => esc_html__(
101
                                            'Text describing what the registrant is consenting to by submitting their personal data in the registration form. To reset to default value, remove all this text and save.',
102
                                            'event_espresso'
103
                                        ),
104
                                        'validation_strategies' => array(new EE_Full_HTML_Validation_Strategy()),
105
                                    )
106
                                ),
107
                            ),
108
                        )
109
                    ),
110
                ),
111
            )
112
        );
113
    }
114
115
116
    /**
117
     * After validating the form data, update the registration config
118
     *
119
     * @param array $submitted_form_data
120
     * @return bool
121
     */
122
    public function process($submitted_form_data = array())
123
    {
124
        try {
125
            $valid_data = parent::process($submitted_form_data);
126
            $reg_config = $this->config->registration;
127
            $reg_config->setConsentCheckboxEnabled($valid_data['enable'] === 'enable-privacy-consent');
128
            $reg_config->setConsentCheckboxLabelText(
129
                $valid_data['enable-privacy-consent']['consent_assertion']
130
            );
131
            return $this->config->update_espresso_config(false, false);
132
        } catch (InvalidFormSubmissionException $e) {
133
            // the form was invalid, it should be re-displayed with errors
134
            return false;
135
        }
136
    }
137
}
138
// End of file PrivacySettingsFormHandler.php
139
// Location: EventEspresso\core\domain\services\admin\privacy\forms/PrivacySettingsFormHandler.php
140