Completed
Branch Gutenberg/event-attendees-bloc... (e27df5)
by
unknown
56:20 queued 41:53
created

PrivacySettingsFormHandler::process()   A

Complexity

Conditions 2
Paths 5

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 10
c 1
b 0
f 0
nc 5
nop 1
dl 0
loc 15
rs 9.4285
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