Completed
Branch GDPR/consent (c6029e)
by
unknown
44:48 queued 29:41
created

PrivacySettingsFormHandler   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 107
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 9

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 107
rs 10
c 1
b 0
f 1
wmc 5
lcom 1
cbo 9

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 1
A generate() 0 49 2
A process() 0 15 2
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
        /**
65
         * @var $reg_config EE_Registration_Config
66
         */
67
        $reg_config = $this->config->registration;
68
        return new EE_Form_Section_Proper(
69
            array(
70
                'name'        => 'privacy_consent_settings',
71
                'subsections' => array(
72
                    'privacy_consent_form_hdr' => new EE_Form_Section_HTML(
73
                        EEH_HTML::h2(esc_html__('Privacy Policy Consent Settings', 'event_espresso'))
74
                    ),
75
                    'enable'                   => new EE_Select_Reveal_Input(
76
                        array(
77
                            'enable-privacy-consent' => esc_html__('Enabled', 'event_espresso'),
78
                            'disable'                => esc_html__('Disabled', 'event_espresso'),
79
                        ),
80
                        array(
81
                            'default'         => $reg_config->isConsentCheckboxEnabled() ? 'enable-privacy-consent'
82
                                : 'disable',
83
                            'html_label_text' => esc_html__('Privacy Consent Checkbox', 'event_espresso'),
84
                            'html_help_text'  => esc_html__(
85
                                'When enabled, a checkbox appears in the registration form requiring users to consent to your site\'s privacy policy.',
86
                                'event_espresso'
87
                            ),
88
                        )
89
                    ),
90
                    'enable-privacy-consent'   => new EE_Form_Section_Proper(
91
                        array(
92
                            'subsections' => array(
93
                                'consent_assertion' => new EE_Text_Area_Input(
94
                                    array(
95
                                        'default'               => $reg_config->getConsentCheckboxLabelText(),
96
                                        'html_label_text'       => esc_html__('Consent Text', 'event_espresso'),
97
                                        'html_help_text'        => esc_html__(
98
                                            'Text describing what the registrant is consenting to by submitting their personal data in the registration form.',
99
                                            'event_espresso'
100
                                        ),
101
                                        'validation_strategies' => array(new EE_Full_HTML_Validation_Strategy()),
102
                                    )
103
                                ),
104
                            ),
105
                        )
106
                    ),
107
                ),
108
            )
109
        );
110
    }
111
112
113
    /**
114
     * After validating the form data, update the registration config
115
     *
116
     * @param array $submitted_form_data
117
     * @return bool
118
     */
119
    public function process($submitted_form_data = array())
120
    {
121
        try {
122
            $valid_data = parent::process($submitted_form_data);
123
            $reg_config = $this->config->registration;
124
            $reg_config->setConsentCheckboxEnabled($valid_data['enable'] === 'enable-privacy-consent');
125
            $reg_config->setConsentCheckboxLabelText(
126
                $valid_data['enable-privacy-consent']['consent_assertion']
127
            );
128
            return $this->config->update_espresso_config(false, false);
129
        } catch (InvalidFormSubmissionException $e) {
130
            //the form was invalid, it show be re-displayed with errors
131
            return false;
132
        }
133
    }
134
}
135
// End of file PrivacySettingsFormHandler.php
136
// Location: EventEspresso\core\domain\services\admin\privacy\forms/PrivacySettingsFormHandler.php
137