Completed
Branch FET/asset-manager (433489)
by
unknown
32:42 queued 18:11
created
core/services/commands/ticket/CancelTicketLineItemCommand.php 1 patch
Indentation   +108 added lines, -108 removed lines patch added patch discarded remove patch
@@ -16,112 +16,112 @@
 block discarded – undo
16 16
 {
17 17
 
18 18
 
19
-    /**
20
-     * @var \EE_Transaction $transaction
21
-     */
22
-    private $transaction;
23
-
24
-    /**
25
-     * @var \EE_Ticket $ticket
26
-     */
27
-    private $ticket;
28
-
29
-    /**
30
-     * @var \EE_Line_Item $ticket_line_item
31
-     */
32
-    protected $ticket_line_item;
33
-
34
-    /**
35
-     * @var int $quantity
36
-     */
37
-    protected $quantity;
38
-
39
-
40
-    /**
41
-     * @param \EE_Registration $registration
42
-     * @param int              $quantity
43
-     */
44
-    public static function fromRegistration(\EE_Registration $registration, $quantity = 1)
45
-    {
46
-        new self(
47
-            $registration->transaction(),
48
-            $registration->ticket(),
49
-            1,
50
-            $registration->ticket_line_item()
51
-        );
52
-    }
53
-
54
-
55
-    /**
56
-     * @param \EE_Line_Item $ticket_line_item
57
-     * @param int           $quantity
58
-     */
59
-    public static function fromTicketLineItem(
60
-        \EE_Line_Item $ticket_line_item,
61
-        $quantity = 1
62
-    ) {
63
-        new self(
64
-            $ticket_line_item->transaction(),
65
-            $ticket_line_item->ticket(),
66
-            $quantity,
67
-            $ticket_line_item
68
-        );
69
-    }
70
-
71
-
72
-    /**
73
-     * CancelTicketLineItemCommand constructor.
74
-     *
75
-     * @param \EE_Transaction $transaction
76
-     * @param \EE_Ticket      $ticket
77
-     * @param int             $quantity
78
-     * @param \EE_Line_Item   $ticket_line_item
79
-     */
80
-    public function __construct(
81
-        \EE_Transaction $transaction,
82
-        \EE_Ticket $ticket,
83
-        $quantity = 1,
84
-        \EE_Line_Item $ticket_line_item = null
85
-    ) {
86
-        $this->transaction = $transaction;
87
-        $this->ticket = $ticket;
88
-        $this->quantity = min(1, absint($quantity));
89
-        $this->ticket_line_item = $ticket_line_item;
90
-    }
91
-
92
-
93
-    /**
94
-     * @return \EE_Transaction
95
-     */
96
-    public function transaction()
97
-    {
98
-        return $this->transaction;
99
-    }
100
-
101
-
102
-    /**
103
-     * @return \EE_Ticket
104
-     */
105
-    public function ticket()
106
-    {
107
-        return $this->ticket;
108
-    }
109
-
110
-
111
-    /**
112
-     * @return \EE_Line_Item
113
-     */
114
-    public function ticketLineItem()
115
-    {
116
-        return $this->ticket_line_item;
117
-    }
118
-
119
-
120
-    /**
121
-     * @return int
122
-     */
123
-    public function quantity()
124
-    {
125
-        return $this->quantity;
126
-    }
19
+	/**
20
+	 * @var \EE_Transaction $transaction
21
+	 */
22
+	private $transaction;
23
+
24
+	/**
25
+	 * @var \EE_Ticket $ticket
26
+	 */
27
+	private $ticket;
28
+
29
+	/**
30
+	 * @var \EE_Line_Item $ticket_line_item
31
+	 */
32
+	protected $ticket_line_item;
33
+
34
+	/**
35
+	 * @var int $quantity
36
+	 */
37
+	protected $quantity;
38
+
39
+
40
+	/**
41
+	 * @param \EE_Registration $registration
42
+	 * @param int              $quantity
43
+	 */
44
+	public static function fromRegistration(\EE_Registration $registration, $quantity = 1)
45
+	{
46
+		new self(
47
+			$registration->transaction(),
48
+			$registration->ticket(),
49
+			1,
50
+			$registration->ticket_line_item()
51
+		);
52
+	}
53
+
54
+
55
+	/**
56
+	 * @param \EE_Line_Item $ticket_line_item
57
+	 * @param int           $quantity
58
+	 */
59
+	public static function fromTicketLineItem(
60
+		\EE_Line_Item $ticket_line_item,
61
+		$quantity = 1
62
+	) {
63
+		new self(
64
+			$ticket_line_item->transaction(),
65
+			$ticket_line_item->ticket(),
66
+			$quantity,
67
+			$ticket_line_item
68
+		);
69
+	}
70
+
71
+
72
+	/**
73
+	 * CancelTicketLineItemCommand constructor.
74
+	 *
75
+	 * @param \EE_Transaction $transaction
76
+	 * @param \EE_Ticket      $ticket
77
+	 * @param int             $quantity
78
+	 * @param \EE_Line_Item   $ticket_line_item
79
+	 */
80
+	public function __construct(
81
+		\EE_Transaction $transaction,
82
+		\EE_Ticket $ticket,
83
+		$quantity = 1,
84
+		\EE_Line_Item $ticket_line_item = null
85
+	) {
86
+		$this->transaction = $transaction;
87
+		$this->ticket = $ticket;
88
+		$this->quantity = min(1, absint($quantity));
89
+		$this->ticket_line_item = $ticket_line_item;
90
+	}
91
+
92
+
93
+	/**
94
+	 * @return \EE_Transaction
95
+	 */
96
+	public function transaction()
97
+	{
98
+		return $this->transaction;
99
+	}
100
+
101
+
102
+	/**
103
+	 * @return \EE_Ticket
104
+	 */
105
+	public function ticket()
106
+	{
107
+		return $this->ticket;
108
+	}
109
+
110
+
111
+	/**
112
+	 * @return \EE_Line_Item
113
+	 */
114
+	public function ticketLineItem()
115
+	{
116
+		return $this->ticket_line_item;
117
+	}
118
+
119
+
120
+	/**
121
+	 * @return int
122
+	 */
123
+	public function quantity()
124
+	{
125
+		return $this->quantity;
126
+	}
127 127
 }
Please login to merge, or discard this patch.
core/services/commands/ticket/CancelTicketLineItemCommandHandler.php 2 patches
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -22,38 +22,38 @@
 block discarded – undo
22 22
 {
23 23
 
24 24
 
25
-    /**
26
-     * @var CancelTicketLineItemService $cancel_ticket_line_item_service
27
-     */
28
-    private $cancel_ticket_line_item_service;
29
-
30
-
31
-    /**
32
-     * Command constructor
33
-     *
34
-     * @param CancelTicketLineItemService $cancel_ticket_line_item_service
35
-     */
36
-    public function __construct(CancelTicketLineItemService $cancel_ticket_line_item_service)
37
-    {
38
-        $this->cancel_ticket_line_item_service = $cancel_ticket_line_item_service;
39
-    }
40
-
41
-
42
-    /**
43
-     * @param \EventEspresso\core\services\commands\CommandInterface $command
44
-     * @return mixed
45
-     */
46
-    public function handle(CommandInterface $command)
47
-    {
48
-        /** @var CancelTicketLineItemCommand $command */
49
-        if (! $command instanceof CancelTicketLineItemCommand) {
50
-            throw new InvalidEntityException(get_class($command), 'CancelTicketLineItemCommand');
51
-        }
52
-        return $this->cancel_ticket_line_item_service->cancel(
53
-            $command->transaction(),
54
-            $command->ticket(),
55
-            $command->quantity(),
56
-            $command->ticketLineItem()
57
-        );
58
-    }
25
+	/**
26
+	 * @var CancelTicketLineItemService $cancel_ticket_line_item_service
27
+	 */
28
+	private $cancel_ticket_line_item_service;
29
+
30
+
31
+	/**
32
+	 * Command constructor
33
+	 *
34
+	 * @param CancelTicketLineItemService $cancel_ticket_line_item_service
35
+	 */
36
+	public function __construct(CancelTicketLineItemService $cancel_ticket_line_item_service)
37
+	{
38
+		$this->cancel_ticket_line_item_service = $cancel_ticket_line_item_service;
39
+	}
40
+
41
+
42
+	/**
43
+	 * @param \EventEspresso\core\services\commands\CommandInterface $command
44
+	 * @return mixed
45
+	 */
46
+	public function handle(CommandInterface $command)
47
+	{
48
+		/** @var CancelTicketLineItemCommand $command */
49
+		if (! $command instanceof CancelTicketLineItemCommand) {
50
+			throw new InvalidEntityException(get_class($command), 'CancelTicketLineItemCommand');
51
+		}
52
+		return $this->cancel_ticket_line_item_service->cancel(
53
+			$command->transaction(),
54
+			$command->ticket(),
55
+			$command->quantity(),
56
+			$command->ticketLineItem()
57
+		);
58
+	}
59 59
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@
 block discarded – undo
51 51
     public function handle(CommandInterface $command)
52 52
     {
53 53
         /** @var CancelTicketLineItemCommand $command */
54
-        if (! $command instanceof CancelTicketLineItemCommand) {
54
+        if ( ! $command instanceof CancelTicketLineItemCommand) {
55 55
             throw new InvalidEntityException(get_class($command), 'CancelTicketLineItemCommand');
56 56
         }
57 57
         return $this->cancel_ticket_line_item_service->cancel(
Please login to merge, or discard this patch.
core/services/commands/ticket/CreateTicketLineItemCommand.php 1 patch
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -16,77 +16,77 @@
 block discarded – undo
16 16
 {
17 17
 
18 18
 
19
-    /**
20
-     * @var \EE_Transaction $transaction
21
-     */
22
-    private $transaction;
23
-
24
-    /**
25
-     * @var \EE_Ticket $ticket
26
-     */
27
-    private $ticket;
28
-
29
-    /**
30
-     * @var int $quantity
31
-     */
32
-    private $quantity = 1;
33
-
34
-    /**
35
-     * @var \EE_Line_Item $ticket_line_item
36
-     */
37
-    protected $ticket_line_item;
38
-
39
-
40
-    /**
41
-     * CreateTicketLineItemCommand constructor.
42
-     *
43
-     * @param \EE_Transaction $transaction
44
-     * @param \EE_Ticket      $ticket
45
-     * @param int             $quantity
46
-     */
47
-    public function __construct(
48
-        \EE_Transaction $transaction,
49
-        \EE_Ticket $ticket,
50
-        $quantity = 1
51
-    ) {
52
-        $this->transaction = $transaction;
53
-        $this->ticket = $ticket;
54
-        $this->quantity = $quantity;
55
-    }
56
-
57
-
58
-    /**
59
-     * @return \EE_Transaction
60
-     */
61
-    public function transaction()
62
-    {
63
-        return $this->transaction;
64
-    }
65
-
66
-
67
-    /**
68
-     * @return \EE_Ticket
69
-     */
70
-    public function ticket()
71
-    {
72
-        return $this->ticket;
73
-    }
74
-
75
-
76
-    /**
77
-     * @return int
78
-     */
79
-    public function quantity()
80
-    {
81
-        return $this->quantity;
82
-    }
83
-
84
-
85
-    /**
86
-     * @return \EE_Line_Item
87
-     */
88
-    public function ticketLineItem()
89
-    {
90
-        return $this->ticket_line_item;
91
-    }
19
+	/**
20
+	 * @var \EE_Transaction $transaction
21
+	 */
22
+	private $transaction;
23
+
24
+	/**
25
+	 * @var \EE_Ticket $ticket
26
+	 */
27
+	private $ticket;
28
+
29
+	/**
30
+	 * @var int $quantity
31
+	 */
32
+	private $quantity = 1;
33
+
34
+	/**
35
+	 * @var \EE_Line_Item $ticket_line_item
36
+	 */
37
+	protected $ticket_line_item;
38
+
39
+
40
+	/**
41
+	 * CreateTicketLineItemCommand constructor.
42
+	 *
43
+	 * @param \EE_Transaction $transaction
44
+	 * @param \EE_Ticket      $ticket
45
+	 * @param int             $quantity
46
+	 */
47
+	public function __construct(
48
+		\EE_Transaction $transaction,
49
+		\EE_Ticket $ticket,
50
+		$quantity = 1
51
+	) {
52
+		$this->transaction = $transaction;
53
+		$this->ticket = $ticket;
54
+		$this->quantity = $quantity;
55
+	}
56
+
57
+
58
+	/**
59
+	 * @return \EE_Transaction
60
+	 */
61
+	public function transaction()
62
+	{
63
+		return $this->transaction;
64
+	}
65
+
66
+
67
+	/**
68
+	 * @return \EE_Ticket
69
+	 */
70
+	public function ticket()
71
+	{
72
+		return $this->ticket;
73
+	}
74
+
75
+
76
+	/**
77
+	 * @return int
78
+	 */
79
+	public function quantity()
80
+	{
81
+		return $this->quantity;
82
+	}
83
+
84
+
85
+	/**
86
+	 * @return \EE_Line_Item
87
+	 */
88
+	public function ticketLineItem()
89
+	{
90
+		return $this->ticket_line_item;
91
+	}
92 92
 }
Please login to merge, or discard this patch.
core/services/commands/attendee/CreateAttendeeCommandHandler.php 2 patches
Indentation   +124 added lines, -124 removed lines patch added patch discarded remove patch
@@ -21,138 +21,138 @@
 block discarded – undo
21 21
 {
22 22
 
23 23
 
24
-    /**
25
-     * @var EEM_Attendee $attendee_model
26
-     */
27
-    protected $attendee_model;
24
+	/**
25
+	 * @var EEM_Attendee $attendee_model
26
+	 */
27
+	protected $attendee_model;
28 28
 
29 29
 
30
-    /**
31
-     * @param EEM_Attendee $attendee_model
32
-     */
33
-    public function __construct(EEM_Attendee $attendee_model)
34
-    {
35
-        $this->attendee_model = $attendee_model;
36
-    }
30
+	/**
31
+	 * @param EEM_Attendee $attendee_model
32
+	 */
33
+	public function __construct(EEM_Attendee $attendee_model)
34
+	{
35
+		$this->attendee_model = $attendee_model;
36
+	}
37 37
 
38 38
 
39
-    /**
40
-     * @param CommandInterface $command
41
-     * @return EE_Attendee
42
-     * @throws EE_Error
43
-     * @throws InvalidEntityException
44
-     */
45
-    public function handle(CommandInterface $command)
46
-    {
47
-        /** @var CreateAttendeeCommand $command */
48
-        if (! $command instanceof CreateAttendeeCommand) {
49
-            throw new InvalidEntityException(get_class($command), 'CreateAttendeeCommand');
50
-        }
51
-        // have we met before?
52
-        $attendee = $this->findExistingAttendee(
53
-            $command->registration(),
54
-            $command->attendeeDetails()
55
-        );
56
-        // did we find an already existing record for this attendee ?
57
-        if ($attendee instanceof EE_Attendee) {
58
-            $attendee = $this->updateExistingAttendeeData(
59
-                $attendee,
60
-                $command->attendeeDetails()
61
-            );
62
-        } else {
63
-            $attendee = $this->createNewAttendee(
64
-                $command->registration(),
65
-                $command->attendeeDetails()
66
-            );
67
-        }
68
-        return $attendee;
69
-    }
39
+	/**
40
+	 * @param CommandInterface $command
41
+	 * @return EE_Attendee
42
+	 * @throws EE_Error
43
+	 * @throws InvalidEntityException
44
+	 */
45
+	public function handle(CommandInterface $command)
46
+	{
47
+		/** @var CreateAttendeeCommand $command */
48
+		if (! $command instanceof CreateAttendeeCommand) {
49
+			throw new InvalidEntityException(get_class($command), 'CreateAttendeeCommand');
50
+		}
51
+		// have we met before?
52
+		$attendee = $this->findExistingAttendee(
53
+			$command->registration(),
54
+			$command->attendeeDetails()
55
+		);
56
+		// did we find an already existing record for this attendee ?
57
+		if ($attendee instanceof EE_Attendee) {
58
+			$attendee = $this->updateExistingAttendeeData(
59
+				$attendee,
60
+				$command->attendeeDetails()
61
+			);
62
+		} else {
63
+			$attendee = $this->createNewAttendee(
64
+				$command->registration(),
65
+				$command->attendeeDetails()
66
+			);
67
+		}
68
+		return $attendee;
69
+	}
70 70
 
71 71
 
72
-    /**
73
-     * find_existing_attendee
74
-     *
75
-     * @param EE_Registration $registration
76
-     * @param  array          $attendee_data
77
-     * @return EE_Attendee
78
-     */
79
-    private function findExistingAttendee(EE_Registration $registration, array $attendee_data)
80
-    {
81
-        $existing_attendee = null;
82
-        // does this attendee already exist in the db ?
83
-        // we're searching using a combination of first name, last name, AND email address
84
-        $ATT_fname = ! empty($attendee_data['ATT_fname'])
85
-            ? $attendee_data['ATT_fname']
86
-            : '';
87
-        $ATT_lname = ! empty($attendee_data['ATT_lname'])
88
-            ? $attendee_data['ATT_lname']
89
-            : '';
90
-        $ATT_email = ! empty($attendee_data['ATT_email'])
91
-            ? $attendee_data['ATT_email']
92
-            : '';
93
-        // but only if those have values
94
-        if ($ATT_fname && $ATT_lname && $ATT_email) {
95
-            $existing_attendee = $this->attendee_model->find_existing_attendee(
96
-                array(
97
-                    'ATT_fname' => $ATT_fname,
98
-                    'ATT_lname' => $ATT_lname,
99
-                    'ATT_email' => $ATT_email,
100
-                )
101
-            );
102
-        }
103
-        return apply_filters(
104
-            'FHEE_EventEspresso_core_services_commands_attendee_CreateAttendeeCommandHandler__findExistingAttendee__existing_attendee',
105
-            $existing_attendee,
106
-            $registration,
107
-            $attendee_data
108
-        );
109
-    }
72
+	/**
73
+	 * find_existing_attendee
74
+	 *
75
+	 * @param EE_Registration $registration
76
+	 * @param  array          $attendee_data
77
+	 * @return EE_Attendee
78
+	 */
79
+	private function findExistingAttendee(EE_Registration $registration, array $attendee_data)
80
+	{
81
+		$existing_attendee = null;
82
+		// does this attendee already exist in the db ?
83
+		// we're searching using a combination of first name, last name, AND email address
84
+		$ATT_fname = ! empty($attendee_data['ATT_fname'])
85
+			? $attendee_data['ATT_fname']
86
+			: '';
87
+		$ATT_lname = ! empty($attendee_data['ATT_lname'])
88
+			? $attendee_data['ATT_lname']
89
+			: '';
90
+		$ATT_email = ! empty($attendee_data['ATT_email'])
91
+			? $attendee_data['ATT_email']
92
+			: '';
93
+		// but only if those have values
94
+		if ($ATT_fname && $ATT_lname && $ATT_email) {
95
+			$existing_attendee = $this->attendee_model->find_existing_attendee(
96
+				array(
97
+					'ATT_fname' => $ATT_fname,
98
+					'ATT_lname' => $ATT_lname,
99
+					'ATT_email' => $ATT_email,
100
+				)
101
+			);
102
+		}
103
+		return apply_filters(
104
+			'FHEE_EventEspresso_core_services_commands_attendee_CreateAttendeeCommandHandler__findExistingAttendee__existing_attendee',
105
+			$existing_attendee,
106
+			$registration,
107
+			$attendee_data
108
+		);
109
+	}
110 110
 
111 111
 
112
-    /**
113
-     * _update_existing_attendee_data
114
-     * in case it has changed since last time they registered for an event
115
-     *
116
-     * @param EE_Attendee $existing_attendee
117
-     * @param  array      $attendee_data
118
-     * @return EE_Attendee
119
-     * @throws EE_Error
120
-     */
121
-    private function updateExistingAttendeeData(EE_Attendee $existing_attendee, array $attendee_data)
122
-    {
123
-        // first remove fname, lname, and email from attendee data
124
-        // because these properties will be exactly the same as the returned attendee object,
125
-        // since they were used in the query to get the attendee object in the first place
126
-        $dont_set = array('ATT_fname', 'ATT_lname', 'ATT_email');
127
-        // now loop thru what's left and add to attendee CPT
128
-        foreach ($attendee_data as $property_name => $property_value) {
129
-            if (! in_array($property_name, $dont_set, true)
130
-                && $this->attendee_model->has_field($property_name)
131
-            ) {
132
-                $existing_attendee->set($property_name, $property_value);
133
-            }
134
-        }
135
-        // better save that now
136
-        $existing_attendee->save();
137
-        return $existing_attendee;
138
-    }
112
+	/**
113
+	 * _update_existing_attendee_data
114
+	 * in case it has changed since last time they registered for an event
115
+	 *
116
+	 * @param EE_Attendee $existing_attendee
117
+	 * @param  array      $attendee_data
118
+	 * @return EE_Attendee
119
+	 * @throws EE_Error
120
+	 */
121
+	private function updateExistingAttendeeData(EE_Attendee $existing_attendee, array $attendee_data)
122
+	{
123
+		// first remove fname, lname, and email from attendee data
124
+		// because these properties will be exactly the same as the returned attendee object,
125
+		// since they were used in the query to get the attendee object in the first place
126
+		$dont_set = array('ATT_fname', 'ATT_lname', 'ATT_email');
127
+		// now loop thru what's left and add to attendee CPT
128
+		foreach ($attendee_data as $property_name => $property_value) {
129
+			if (! in_array($property_name, $dont_set, true)
130
+				&& $this->attendee_model->has_field($property_name)
131
+			) {
132
+				$existing_attendee->set($property_name, $property_value);
133
+			}
134
+		}
135
+		// better save that now
136
+		$existing_attendee->save();
137
+		return $existing_attendee;
138
+	}
139 139
 
140 140
 
141
-    /**
142
-     * create_new_attendee
143
-     *
144
-     * @param EE_Registration $registration
145
-     * @param  array          $attendee_data
146
-     * @return EE_Attendee
147
-     * @throws EE_Error
148
-     */
149
-    private function createNewAttendee(EE_Registration $registration, array $attendee_data)
150
-    {
151
-        // create new attendee object
152
-        $new_attendee = EE_Attendee::new_instance($attendee_data);
153
-        // set author to event creator
154
-        $new_attendee->set('ATT_author', $registration->event()->wp_user());
155
-        $new_attendee->save();
156
-        return $new_attendee;
157
-    }
141
+	/**
142
+	 * create_new_attendee
143
+	 *
144
+	 * @param EE_Registration $registration
145
+	 * @param  array          $attendee_data
146
+	 * @return EE_Attendee
147
+	 * @throws EE_Error
148
+	 */
149
+	private function createNewAttendee(EE_Registration $registration, array $attendee_data)
150
+	{
151
+		// create new attendee object
152
+		$new_attendee = EE_Attendee::new_instance($attendee_data);
153
+		// set author to event creator
154
+		$new_attendee->set('ATT_author', $registration->event()->wp_user());
155
+		$new_attendee->save();
156
+		return $new_attendee;
157
+	}
158 158
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
     public function handle(CommandInterface $command)
46 46
     {
47 47
         /** @var CreateAttendeeCommand $command */
48
-        if (! $command instanceof CreateAttendeeCommand) {
48
+        if ( ! $command instanceof CreateAttendeeCommand) {
49 49
             throw new InvalidEntityException(get_class($command), 'CreateAttendeeCommand');
50 50
         }
51 51
         // have we met before?
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
         $dont_set = array('ATT_fname', 'ATT_lname', 'ATT_email');
127 127
         // now loop thru what's left and add to attendee CPT
128 128
         foreach ($attendee_data as $property_name => $property_value) {
129
-            if (! in_array($property_name, $dont_set, true)
129
+            if ( ! in_array($property_name, $dont_set, true)
130 130
                 && $this->attendee_model->has_field($property_name)
131 131
             ) {
132 132
                 $existing_attendee->set($property_name, $property_value);
Please login to merge, or discard this patch.
core/services/commands/attendee/CreateAttendeeCommand.php 1 patch
Indentation   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -20,62 +20,62 @@
 block discarded – undo
20 20
 class CreateAttendeeCommand extends Command implements CommandRequiresCapCheckInterface
21 21
 {
22 22
 
23
-    /**
24
-     * array of details where keys are names of EEM_Attendee model fields
25
-     *
26
-     * @var array $attendee_details
27
-     */
28
-    protected $attendee_details;
23
+	/**
24
+	 * array of details where keys are names of EEM_Attendee model fields
25
+	 *
26
+	 * @var array $attendee_details
27
+	 */
28
+	protected $attendee_details;
29 29
 
30
-    /**
31
-     * an existing registration to associate this attendee with
32
-     *
33
-     * @var EE_Registration $registration
34
-     */
35
-    protected $registration;
30
+	/**
31
+	 * an existing registration to associate this attendee with
32
+	 *
33
+	 * @var EE_Registration $registration
34
+	 */
35
+	protected $registration;
36 36
 
37 37
 
38
-    /**
39
-     * CreateAttendeeCommand constructor.
40
-     *
41
-     * @param array           $attendee_details
42
-     * @param EE_Registration $registration
43
-     */
44
-    public function __construct(array $attendee_details, EE_Registration $registration)
45
-    {
46
-        $this->attendee_details = $attendee_details;
47
-        $this->registration = $registration;
48
-    }
38
+	/**
39
+	 * CreateAttendeeCommand constructor.
40
+	 *
41
+	 * @param array           $attendee_details
42
+	 * @param EE_Registration $registration
43
+	 */
44
+	public function __construct(array $attendee_details, EE_Registration $registration)
45
+	{
46
+		$this->attendee_details = $attendee_details;
47
+		$this->registration = $registration;
48
+	}
49 49
 
50 50
 
51
-    /**
52
-     * @return array
53
-     */
54
-    public function attendeeDetails()
55
-    {
56
-        return $this->attendee_details;
57
-    }
51
+	/**
52
+	 * @return array
53
+	 */
54
+	public function attendeeDetails()
55
+	{
56
+		return $this->attendee_details;
57
+	}
58 58
 
59 59
 
60
-    /**
61
-     * @return EE_Registration
62
-     */
63
-    public function registration()
64
-    {
65
-        return $this->registration;
66
-    }
60
+	/**
61
+	 * @return EE_Registration
62
+	 */
63
+	public function registration()
64
+	{
65
+		return $this->registration;
66
+	}
67 67
 
68 68
 
69
-    /**
70
-     * @return CapCheckInterface
71
-     * @throws InvalidDataTypeException
72
-     */
73
-    public function getCapCheck()
74
-    {
75
-        // need cap for non-AJAX admin requests
76
-        if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) {
77
-            return new CapCheck('ee_edit_contacts', 'create_new_contact');
78
-        }
79
-        return new PublicCapabilities('', 'create_new_contact');
80
-    }
69
+	/**
70
+	 * @return CapCheckInterface
71
+	 * @throws InvalidDataTypeException
72
+	 */
73
+	public function getCapCheck()
74
+	{
75
+		// need cap for non-AJAX admin requests
76
+		if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) {
77
+			return new CapCheck('ee_edit_contacts', 'create_new_contact');
78
+		}
79
+		return new PublicCapabilities('', 'create_new_contact');
80
+	}
81 81
 }
Please login to merge, or discard this patch.
core/libraries/form_sections/form_handlers/FormHandler.php 2 patches
Indentation   +612 added lines, -612 removed lines patch added patch discarded remove patch
@@ -28,616 +28,616 @@
 block discarded – undo
28 28
 abstract class FormHandler implements FormHandlerInterface
29 29
 {
30 30
 
31
-    /**
32
-     * will add opening and closing HTML form tags as well as a submit button
33
-     */
34
-    const ADD_FORM_TAGS_AND_SUBMIT = 'add_form_tags_and_submit';
35
-
36
-    /**
37
-     * will add opening and closing HTML form tags but NOT a submit button
38
-     */
39
-    const ADD_FORM_TAGS_ONLY = 'add_form_tags_only';
40
-
41
-    /**
42
-     * will NOT add opening and closing HTML form tags but will add a submit button
43
-     */
44
-    const ADD_FORM_SUBMIT_ONLY = 'add_form_submit_only';
45
-
46
-    /**
47
-     * will NOT add opening and closing HTML form tags NOR a submit button
48
-     */
49
-    const DO_NOT_SETUP_FORM = 'do_not_setup_form';
50
-
51
-    /**
52
-     * if set to false, then this form has no displayable content,
53
-     * and will only be used for processing data sent passed via GET or POST
54
-     * defaults to true ( ie: form has displayable content )
55
-     *
56
-     * @var boolean $displayable
57
-     */
58
-    private $displayable = true;
59
-
60
-    /**
61
-     * @var string $form_name
62
-     */
63
-    private $form_name;
64
-
65
-    /**
66
-     * @var string $admin_name
67
-     */
68
-    private $admin_name;
69
-
70
-    /**
71
-     * @var string $slug
72
-     */
73
-    private $slug;
74
-
75
-    /**
76
-     * @var string $submit_btn_text
77
-     */
78
-    private $submit_btn_text;
79
-
80
-    /**
81
-     * @var string $form_action
82
-     */
83
-    private $form_action;
84
-
85
-    /**
86
-     * form params in key value pairs
87
-     * can be added to form action URL or as hidden inputs
88
-     *
89
-     * @var array $form_args
90
-     */
91
-    private $form_args = array();
92
-
93
-    /**
94
-     * value of one of the string constant above
95
-     *
96
-     * @var string $form_config
97
-     */
98
-    private $form_config;
99
-
100
-    /**
101
-     * whether or not the form was determined to be invalid
102
-     *
103
-     * @var boolean $form_has_errors
104
-     */
105
-    private $form_has_errors;
106
-
107
-    /**
108
-     * the absolute top level form section being used on the page
109
-     *
110
-     * @var EE_Form_Section_Proper $form
111
-     */
112
-    private $form;
113
-
114
-    /**
115
-     * @var EE_Registry $registry
116
-     */
117
-    protected $registry;
118
-
119
-    // phpcs:disable PEAR.Functions.ValidDefaultValue.NotAtEnd
120
-    /**
121
-     * Form constructor.
122
-     *
123
-     * @param string      $form_name
124
-     * @param string      $admin_name
125
-     * @param string      $slug
126
-     * @param string      $form_action
127
-     * @param string      $form_config
128
-     * @param EE_Registry $registry
129
-     * @throws InvalidDataTypeException
130
-     * @throws DomainException
131
-     * @throws InvalidArgumentException
132
-     */
133
-    public function __construct(
134
-        $form_name,
135
-        $admin_name,
136
-        $slug,
137
-        $form_action = '',
138
-        $form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
139
-        EE_Registry $registry
140
-    ) {
141
-        $this->setFormName($form_name);
142
-        $this->setAdminName($admin_name);
143
-        $this->setSlug($slug);
144
-        $this->setFormAction($form_action);
145
-        $this->setFormConfig($form_config);
146
-        $this->setSubmitBtnText(esc_html__('Submit', 'event_espresso'));
147
-        $this->registry = $registry;
148
-    }
149
-
150
-
151
-    /**
152
-     * @return array
153
-     */
154
-    public static function getFormConfigConstants()
155
-    {
156
-        return array(
157
-            FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
158
-            FormHandler::ADD_FORM_TAGS_ONLY,
159
-            FormHandler::ADD_FORM_SUBMIT_ONLY,
160
-            FormHandler::DO_NOT_SETUP_FORM,
161
-        );
162
-    }
163
-
164
-
165
-    /**
166
-     * @param bool $for_display
167
-     * @return EE_Form_Section_Proper
168
-     * @throws EE_Error
169
-     * @throws LogicException
170
-     */
171
-    public function form($for_display = false)
172
-    {
173
-        if (! $this->formIsValid()) {
174
-            return null;
175
-        }
176
-        if ($for_display) {
177
-            $form_config = $this->formConfig();
178
-            if ($form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
179
-                || $form_config === FormHandler::ADD_FORM_SUBMIT_ONLY
180
-            ) {
181
-                $this->appendSubmitButton();
182
-                $this->clearFormButtonFloats();
183
-            }
184
-        }
185
-        return $this->form;
186
-    }
187
-
188
-
189
-    /**
190
-     * @return boolean
191
-     * @throws LogicException
192
-     */
193
-    public function formIsValid()
194
-    {
195
-        if ($this->form instanceof EE_Form_Section_Proper) {
196
-            return true;
197
-        }
198
-        $form = apply_filters(
199
-            'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__formIsValid__generated_form_object',
200
-            $this->generate(),
201
-            $this
202
-        );
203
-        if ($this->verifyForm($form)) {
204
-            $this->setForm($form);
205
-        }
206
-        return true;
207
-    }
208
-
209
-
210
-    /**
211
-     * @param EE_Form_Section_Proper|null $form
212
-     * @return bool
213
-     * @throws LogicException
214
-     */
215
-    public function verifyForm(EE_Form_Section_Proper $form = null)
216
-    {
217
-        $form = $form !== null ? $form : $this->form;
218
-        if ($form instanceof EE_Form_Section_Proper) {
219
-            return true;
220
-        }
221
-        throw new LogicException(
222
-            sprintf(
223
-                esc_html__('The "%1$s" form is invalid or missing. %2$s', 'event_espresso'),
224
-                $this->form_name,
225
-                var_export($form, true)
226
-            )
227
-        );
228
-    }
229
-
230
-
231
-    /**
232
-     * @param EE_Form_Section_Proper $form
233
-     */
234
-    public function setForm(EE_Form_Section_Proper $form)
235
-    {
236
-        $this->form = $form;
237
-    }
238
-
239
-
240
-    /**
241
-     * @return boolean
242
-     */
243
-    public function displayable()
244
-    {
245
-        return $this->displayable;
246
-    }
247
-
248
-
249
-    /**
250
-     * @param boolean $displayable
251
-     */
252
-    public function setDisplayable($displayable = false)
253
-    {
254
-        $this->displayable = filter_var($displayable, FILTER_VALIDATE_BOOLEAN);
255
-    }
256
-
257
-
258
-    /**
259
-     * a public name for the form that can be displayed on the frontend of a site
260
-     *
261
-     * @return string
262
-     */
263
-    public function formName()
264
-    {
265
-        return $this->form_name;
266
-    }
267
-
268
-
269
-    /**
270
-     * @param string $form_name
271
-     * @throws InvalidDataTypeException
272
-     */
273
-    public function setFormName($form_name)
274
-    {
275
-        if (! is_string($form_name)) {
276
-            throw new InvalidDataTypeException('$form_name', $form_name, 'string');
277
-        }
278
-        $this->form_name = $form_name;
279
-    }
280
-
281
-
282
-    /**
283
-     * a public name for the form that can be displayed, but only in the admin
284
-     *
285
-     * @return string
286
-     */
287
-    public function adminName()
288
-    {
289
-        return $this->admin_name;
290
-    }
291
-
292
-
293
-    /**
294
-     * @param string $admin_name
295
-     * @throws InvalidDataTypeException
296
-     */
297
-    public function setAdminName($admin_name)
298
-    {
299
-        if (! is_string($admin_name)) {
300
-            throw new InvalidDataTypeException('$admin_name', $admin_name, 'string');
301
-        }
302
-        $this->admin_name = $admin_name;
303
-    }
304
-
305
-
306
-    /**
307
-     * a URL friendly string that can be used for identifying the form
308
-     *
309
-     * @return string
310
-     */
311
-    public function slug()
312
-    {
313
-        return $this->slug;
314
-    }
315
-
316
-
317
-    /**
318
-     * @param string $slug
319
-     * @throws InvalidDataTypeException
320
-     */
321
-    public function setSlug($slug)
322
-    {
323
-        if (! is_string($slug)) {
324
-            throw new InvalidDataTypeException('$slug', $slug, 'string');
325
-        }
326
-        $this->slug = $slug;
327
-    }
328
-
329
-
330
-    /**
331
-     * @return string
332
-     */
333
-    public function submitBtnText()
334
-    {
335
-        return $this->submit_btn_text;
336
-    }
337
-
338
-
339
-    /**
340
-     * @param string $submit_btn_text
341
-     * @throws InvalidDataTypeException
342
-     * @throws InvalidArgumentException
343
-     */
344
-    public function setSubmitBtnText($submit_btn_text)
345
-    {
346
-        if (! is_string($submit_btn_text)) {
347
-            throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string');
348
-        }
349
-        if (empty($submit_btn_text)) {
350
-            throw new InvalidArgumentException(
351
-                esc_html__('Can not set Submit button text because an empty string was provided.', 'event_espresso')
352
-            );
353
-        }
354
-        $this->submit_btn_text = $submit_btn_text;
355
-    }
356
-
357
-
358
-    /**
359
-     * @return string
360
-     */
361
-    public function formAction()
362
-    {
363
-        return ! empty($this->form_args)
364
-            ? add_query_arg($this->form_args, $this->form_action)
365
-            : $this->form_action;
366
-    }
367
-
368
-
369
-    /**
370
-     * @param string $form_action
371
-     * @throws InvalidDataTypeException
372
-     */
373
-    public function setFormAction($form_action)
374
-    {
375
-        if (! is_string($form_action)) {
376
-            throw new InvalidDataTypeException('$form_action', $form_action, 'string');
377
-        }
378
-        $this->form_action = $form_action;
379
-    }
380
-
381
-
382
-    /**
383
-     * @param array $form_args
384
-     * @throws InvalidDataTypeException
385
-     * @throws InvalidArgumentException
386
-     */
387
-    public function addFormActionArgs($form_args = array())
388
-    {
389
-        if (is_object($form_args)) {
390
-            throw new InvalidDataTypeException(
391
-                '$form_args',
392
-                $form_args,
393
-                'anything other than an object was expected.'
394
-            );
395
-        }
396
-        if (empty($form_args)) {
397
-            throw new InvalidArgumentException(
398
-                esc_html__('The redirect arguments can not be an empty array.', 'event_espresso')
399
-            );
400
-        }
401
-        $this->form_args = array_merge($this->form_args, $form_args);
402
-    }
403
-
404
-
405
-    /**
406
-     * @return string
407
-     */
408
-    public function formConfig()
409
-    {
410
-        return $this->form_config;
411
-    }
412
-
413
-
414
-    /**
415
-     * @param string $form_config
416
-     * @throws DomainException
417
-     */
418
-    public function setFormConfig($form_config)
419
-    {
420
-        if (! in_array(
421
-            $form_config,
422
-            array(
423
-                FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
424
-                FormHandler::ADD_FORM_TAGS_ONLY,
425
-                FormHandler::ADD_FORM_SUBMIT_ONLY,
426
-                FormHandler::DO_NOT_SETUP_FORM,
427
-            ),
428
-            true
429
-        )
430
-        ) {
431
-            throw new DomainException(
432
-                sprintf(
433
-                    esc_html__(
434
-                        '"%1$s" is not a valid value for the form config. Please use one of the class constants on \EventEspresso\core\libraries\form_sections\form_handlers\Form',
435
-                        'event_espresso'
436
-                    ),
437
-                    $form_config
438
-                )
439
-            );
440
-        }
441
-        $this->form_config = $form_config;
442
-    }
443
-
444
-
445
-    /**
446
-     * called after the form is instantiated
447
-     * and used for performing any logic that needs to occur early
448
-     * before any of the other methods are called.
449
-     * returns true if everything is ok to proceed,
450
-     * and false if no further form logic should be implemented
451
-     *
452
-     * @return boolean
453
-     */
454
-    public function initialize()
455
-    {
456
-        $this->form_has_errors = EE_Error::has_error(true);
457
-        return true;
458
-    }
459
-
460
-
461
-    /**
462
-     * used for setting up css and js
463
-     *
464
-     * @return void
465
-     * @throws LogicException
466
-     * @throws EE_Error
467
-     */
468
-    public function enqueueStylesAndScripts()
469
-    {
470
-        $this->form()->enqueue_js();
471
-    }
472
-
473
-
474
-    /**
475
-     * creates and returns the actual form
476
-     *
477
-     * @return EE_Form_Section_Proper
478
-     */
479
-    abstract public function generate();
480
-
481
-
482
-    /**
483
-     * creates and returns an EE_Submit_Input labeled "Submit"
484
-     *
485
-     * @param string $text
486
-     * @return EE_Submit_Input
487
-     */
488
-    public function generateSubmitButton($text = '')
489
-    {
490
-        $text = ! empty($text) ? $text : $this->submitBtnText();
491
-        return new EE_Submit_Input(
492
-            array(
493
-                'html_name'             => 'ee-form-submit-' . $this->slug(),
494
-                'html_id'               => 'ee-form-submit-' . $this->slug(),
495
-                'html_class'            => 'ee-form-submit',
496
-                'html_label'            => ' ',
497
-                'other_html_attributes' => ' rel="' . $this->slug() . '"',
498
-                'default'               => $text,
499
-            )
500
-        );
501
-    }
502
-
503
-
504
-    /**
505
-     * calls generateSubmitButton() and appends it onto the form along with a float clearing div
506
-     *
507
-     * @param string $text
508
-     * @return void
509
-     * @throws EE_Error
510
-     */
511
-    public function appendSubmitButton($text = '')
512
-    {
513
-        if ($this->form->subsection_exists($this->slug() . '-submit-btn')) {
514
-            return;
515
-        }
516
-        $this->form->add_subsections(
517
-            array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)),
518
-            null,
519
-            false
520
-        );
521
-    }
522
-
523
-
524
-    /**
525
-     * creates and returns an EE_Submit_Input labeled "Cancel"
526
-     *
527
-     * @param string $text
528
-     * @return EE_Submit_Input
529
-     */
530
-    public function generateCancelButton($text = '')
531
-    {
532
-        $cancel_button = new EE_Submit_Input(
533
-            array(
534
-                'html_name'             => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!!
535
-                'html_id'               => 'ee-cancel-form-' . $this->slug(),
536
-                'html_class'            => 'ee-cancel-form',
537
-                'html_label'            => ' ',
538
-                'other_html_attributes' => ' rel="' . $this->slug() . '"',
539
-                'default'               => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'),
540
-            )
541
-        );
542
-        $cancel_button->set_button_css_attributes(false);
543
-        return $cancel_button;
544
-    }
545
-
546
-
547
-    /**
548
-     * appends a float clearing div onto end of form
549
-     *
550
-     * @return void
551
-     * @throws EE_Error
552
-     */
553
-    public function clearFormButtonFloats()
554
-    {
555
-        $this->form->add_subsections(
556
-            array(
557
-                'clear-submit-btn-float' => new EE_Form_Section_HTML(
558
-                    EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx()
559
-                ),
560
-            ),
561
-            null,
562
-            false
563
-        );
564
-    }
565
-
566
-
567
-    /**
568
-     * takes the generated form and displays it along with ony other non-form HTML that may be required
569
-     * returns a string of HTML that can be directly echoed in a template
570
-     *
571
-     * @return string
572
-     * @throws \InvalidArgumentException
573
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
574
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
575
-     * @throws LogicException
576
-     * @throws EE_Error
577
-     */
578
-    public function display()
579
-    {
580
-        $form_html = apply_filters(
581
-            'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__before_form',
582
-            ''
583
-        );
584
-        $form_config = $this->formConfig();
585
-        if ($form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
586
-            || $form_config === FormHandler::ADD_FORM_TAGS_ONLY
587
-        ) {
588
-            $form_html .= $this->form()->form_open($this->formAction());
589
-        }
590
-        $form_html .= $this->form(true)->get_html($this->form_has_errors);
591
-        if ($form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
592
-            || $form_config === FormHandler::ADD_FORM_TAGS_ONLY
593
-        ) {
594
-            $form_html .= $this->form()->form_close();
595
-        }
596
-        $form_html .= apply_filters(
597
-            'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__after_form',
598
-            ''
599
-        );
600
-        return $form_html;
601
-    }
602
-
603
-
604
-    /**
605
-     * handles processing the form submission
606
-     * returns true or false depending on whether the form was processed successfully or not
607
-     *
608
-     * @param array $submitted_form_data
609
-     * @return array
610
-     * @throws \InvalidArgumentException
611
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
612
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
613
-     * @throws EE_Error
614
-     * @throws LogicException
615
-     * @throws InvalidFormSubmissionException
616
-     */
617
-    public function process($submitted_form_data = array())
618
-    {
619
-        if (! $this->form()->was_submitted($submitted_form_data)) {
620
-            throw new InvalidFormSubmissionException($this->form_name);
621
-        }
622
-        $this->form(true)->receive_form_submission($submitted_form_data);
623
-        if (! $this->form()->is_valid()) {
624
-            throw new InvalidFormSubmissionException(
625
-                $this->form_name,
626
-                sprintf(
627
-                    esc_html__(
628
-                        'The "%1$s" form is invalid. Please correct the following errors and resubmit: %2$s %3$s',
629
-                        'event_espresso'
630
-                    ),
631
-                    $this->form_name,
632
-                    '<br />',
633
-                    implode('<br />', $this->form()->get_validation_errors_accumulated())
634
-                )
635
-            );
636
-        }
637
-        return apply_filters(
638
-            'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__process__valid_data',
639
-            $this->form()->valid_data(),
640
-            $this
641
-        );
642
-    }
31
+	/**
32
+	 * will add opening and closing HTML form tags as well as a submit button
33
+	 */
34
+	const ADD_FORM_TAGS_AND_SUBMIT = 'add_form_tags_and_submit';
35
+
36
+	/**
37
+	 * will add opening and closing HTML form tags but NOT a submit button
38
+	 */
39
+	const ADD_FORM_TAGS_ONLY = 'add_form_tags_only';
40
+
41
+	/**
42
+	 * will NOT add opening and closing HTML form tags but will add a submit button
43
+	 */
44
+	const ADD_FORM_SUBMIT_ONLY = 'add_form_submit_only';
45
+
46
+	/**
47
+	 * will NOT add opening and closing HTML form tags NOR a submit button
48
+	 */
49
+	const DO_NOT_SETUP_FORM = 'do_not_setup_form';
50
+
51
+	/**
52
+	 * if set to false, then this form has no displayable content,
53
+	 * and will only be used for processing data sent passed via GET or POST
54
+	 * defaults to true ( ie: form has displayable content )
55
+	 *
56
+	 * @var boolean $displayable
57
+	 */
58
+	private $displayable = true;
59
+
60
+	/**
61
+	 * @var string $form_name
62
+	 */
63
+	private $form_name;
64
+
65
+	/**
66
+	 * @var string $admin_name
67
+	 */
68
+	private $admin_name;
69
+
70
+	/**
71
+	 * @var string $slug
72
+	 */
73
+	private $slug;
74
+
75
+	/**
76
+	 * @var string $submit_btn_text
77
+	 */
78
+	private $submit_btn_text;
79
+
80
+	/**
81
+	 * @var string $form_action
82
+	 */
83
+	private $form_action;
84
+
85
+	/**
86
+	 * form params in key value pairs
87
+	 * can be added to form action URL or as hidden inputs
88
+	 *
89
+	 * @var array $form_args
90
+	 */
91
+	private $form_args = array();
92
+
93
+	/**
94
+	 * value of one of the string constant above
95
+	 *
96
+	 * @var string $form_config
97
+	 */
98
+	private $form_config;
99
+
100
+	/**
101
+	 * whether or not the form was determined to be invalid
102
+	 *
103
+	 * @var boolean $form_has_errors
104
+	 */
105
+	private $form_has_errors;
106
+
107
+	/**
108
+	 * the absolute top level form section being used on the page
109
+	 *
110
+	 * @var EE_Form_Section_Proper $form
111
+	 */
112
+	private $form;
113
+
114
+	/**
115
+	 * @var EE_Registry $registry
116
+	 */
117
+	protected $registry;
118
+
119
+	// phpcs:disable PEAR.Functions.ValidDefaultValue.NotAtEnd
120
+	/**
121
+	 * Form constructor.
122
+	 *
123
+	 * @param string      $form_name
124
+	 * @param string      $admin_name
125
+	 * @param string      $slug
126
+	 * @param string      $form_action
127
+	 * @param string      $form_config
128
+	 * @param EE_Registry $registry
129
+	 * @throws InvalidDataTypeException
130
+	 * @throws DomainException
131
+	 * @throws InvalidArgumentException
132
+	 */
133
+	public function __construct(
134
+		$form_name,
135
+		$admin_name,
136
+		$slug,
137
+		$form_action = '',
138
+		$form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
139
+		EE_Registry $registry
140
+	) {
141
+		$this->setFormName($form_name);
142
+		$this->setAdminName($admin_name);
143
+		$this->setSlug($slug);
144
+		$this->setFormAction($form_action);
145
+		$this->setFormConfig($form_config);
146
+		$this->setSubmitBtnText(esc_html__('Submit', 'event_espresso'));
147
+		$this->registry = $registry;
148
+	}
149
+
150
+
151
+	/**
152
+	 * @return array
153
+	 */
154
+	public static function getFormConfigConstants()
155
+	{
156
+		return array(
157
+			FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
158
+			FormHandler::ADD_FORM_TAGS_ONLY,
159
+			FormHandler::ADD_FORM_SUBMIT_ONLY,
160
+			FormHandler::DO_NOT_SETUP_FORM,
161
+		);
162
+	}
163
+
164
+
165
+	/**
166
+	 * @param bool $for_display
167
+	 * @return EE_Form_Section_Proper
168
+	 * @throws EE_Error
169
+	 * @throws LogicException
170
+	 */
171
+	public function form($for_display = false)
172
+	{
173
+		if (! $this->formIsValid()) {
174
+			return null;
175
+		}
176
+		if ($for_display) {
177
+			$form_config = $this->formConfig();
178
+			if ($form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
179
+				|| $form_config === FormHandler::ADD_FORM_SUBMIT_ONLY
180
+			) {
181
+				$this->appendSubmitButton();
182
+				$this->clearFormButtonFloats();
183
+			}
184
+		}
185
+		return $this->form;
186
+	}
187
+
188
+
189
+	/**
190
+	 * @return boolean
191
+	 * @throws LogicException
192
+	 */
193
+	public function formIsValid()
194
+	{
195
+		if ($this->form instanceof EE_Form_Section_Proper) {
196
+			return true;
197
+		}
198
+		$form = apply_filters(
199
+			'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__formIsValid__generated_form_object',
200
+			$this->generate(),
201
+			$this
202
+		);
203
+		if ($this->verifyForm($form)) {
204
+			$this->setForm($form);
205
+		}
206
+		return true;
207
+	}
208
+
209
+
210
+	/**
211
+	 * @param EE_Form_Section_Proper|null $form
212
+	 * @return bool
213
+	 * @throws LogicException
214
+	 */
215
+	public function verifyForm(EE_Form_Section_Proper $form = null)
216
+	{
217
+		$form = $form !== null ? $form : $this->form;
218
+		if ($form instanceof EE_Form_Section_Proper) {
219
+			return true;
220
+		}
221
+		throw new LogicException(
222
+			sprintf(
223
+				esc_html__('The "%1$s" form is invalid or missing. %2$s', 'event_espresso'),
224
+				$this->form_name,
225
+				var_export($form, true)
226
+			)
227
+		);
228
+	}
229
+
230
+
231
+	/**
232
+	 * @param EE_Form_Section_Proper $form
233
+	 */
234
+	public function setForm(EE_Form_Section_Proper $form)
235
+	{
236
+		$this->form = $form;
237
+	}
238
+
239
+
240
+	/**
241
+	 * @return boolean
242
+	 */
243
+	public function displayable()
244
+	{
245
+		return $this->displayable;
246
+	}
247
+
248
+
249
+	/**
250
+	 * @param boolean $displayable
251
+	 */
252
+	public function setDisplayable($displayable = false)
253
+	{
254
+		$this->displayable = filter_var($displayable, FILTER_VALIDATE_BOOLEAN);
255
+	}
256
+
257
+
258
+	/**
259
+	 * a public name for the form that can be displayed on the frontend of a site
260
+	 *
261
+	 * @return string
262
+	 */
263
+	public function formName()
264
+	{
265
+		return $this->form_name;
266
+	}
267
+
268
+
269
+	/**
270
+	 * @param string $form_name
271
+	 * @throws InvalidDataTypeException
272
+	 */
273
+	public function setFormName($form_name)
274
+	{
275
+		if (! is_string($form_name)) {
276
+			throw new InvalidDataTypeException('$form_name', $form_name, 'string');
277
+		}
278
+		$this->form_name = $form_name;
279
+	}
280
+
281
+
282
+	/**
283
+	 * a public name for the form that can be displayed, but only in the admin
284
+	 *
285
+	 * @return string
286
+	 */
287
+	public function adminName()
288
+	{
289
+		return $this->admin_name;
290
+	}
291
+
292
+
293
+	/**
294
+	 * @param string $admin_name
295
+	 * @throws InvalidDataTypeException
296
+	 */
297
+	public function setAdminName($admin_name)
298
+	{
299
+		if (! is_string($admin_name)) {
300
+			throw new InvalidDataTypeException('$admin_name', $admin_name, 'string');
301
+		}
302
+		$this->admin_name = $admin_name;
303
+	}
304
+
305
+
306
+	/**
307
+	 * a URL friendly string that can be used for identifying the form
308
+	 *
309
+	 * @return string
310
+	 */
311
+	public function slug()
312
+	{
313
+		return $this->slug;
314
+	}
315
+
316
+
317
+	/**
318
+	 * @param string $slug
319
+	 * @throws InvalidDataTypeException
320
+	 */
321
+	public function setSlug($slug)
322
+	{
323
+		if (! is_string($slug)) {
324
+			throw new InvalidDataTypeException('$slug', $slug, 'string');
325
+		}
326
+		$this->slug = $slug;
327
+	}
328
+
329
+
330
+	/**
331
+	 * @return string
332
+	 */
333
+	public function submitBtnText()
334
+	{
335
+		return $this->submit_btn_text;
336
+	}
337
+
338
+
339
+	/**
340
+	 * @param string $submit_btn_text
341
+	 * @throws InvalidDataTypeException
342
+	 * @throws InvalidArgumentException
343
+	 */
344
+	public function setSubmitBtnText($submit_btn_text)
345
+	{
346
+		if (! is_string($submit_btn_text)) {
347
+			throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string');
348
+		}
349
+		if (empty($submit_btn_text)) {
350
+			throw new InvalidArgumentException(
351
+				esc_html__('Can not set Submit button text because an empty string was provided.', 'event_espresso')
352
+			);
353
+		}
354
+		$this->submit_btn_text = $submit_btn_text;
355
+	}
356
+
357
+
358
+	/**
359
+	 * @return string
360
+	 */
361
+	public function formAction()
362
+	{
363
+		return ! empty($this->form_args)
364
+			? add_query_arg($this->form_args, $this->form_action)
365
+			: $this->form_action;
366
+	}
367
+
368
+
369
+	/**
370
+	 * @param string $form_action
371
+	 * @throws InvalidDataTypeException
372
+	 */
373
+	public function setFormAction($form_action)
374
+	{
375
+		if (! is_string($form_action)) {
376
+			throw new InvalidDataTypeException('$form_action', $form_action, 'string');
377
+		}
378
+		$this->form_action = $form_action;
379
+	}
380
+
381
+
382
+	/**
383
+	 * @param array $form_args
384
+	 * @throws InvalidDataTypeException
385
+	 * @throws InvalidArgumentException
386
+	 */
387
+	public function addFormActionArgs($form_args = array())
388
+	{
389
+		if (is_object($form_args)) {
390
+			throw new InvalidDataTypeException(
391
+				'$form_args',
392
+				$form_args,
393
+				'anything other than an object was expected.'
394
+			);
395
+		}
396
+		if (empty($form_args)) {
397
+			throw new InvalidArgumentException(
398
+				esc_html__('The redirect arguments can not be an empty array.', 'event_espresso')
399
+			);
400
+		}
401
+		$this->form_args = array_merge($this->form_args, $form_args);
402
+	}
403
+
404
+
405
+	/**
406
+	 * @return string
407
+	 */
408
+	public function formConfig()
409
+	{
410
+		return $this->form_config;
411
+	}
412
+
413
+
414
+	/**
415
+	 * @param string $form_config
416
+	 * @throws DomainException
417
+	 */
418
+	public function setFormConfig($form_config)
419
+	{
420
+		if (! in_array(
421
+			$form_config,
422
+			array(
423
+				FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
424
+				FormHandler::ADD_FORM_TAGS_ONLY,
425
+				FormHandler::ADD_FORM_SUBMIT_ONLY,
426
+				FormHandler::DO_NOT_SETUP_FORM,
427
+			),
428
+			true
429
+		)
430
+		) {
431
+			throw new DomainException(
432
+				sprintf(
433
+					esc_html__(
434
+						'"%1$s" is not a valid value for the form config. Please use one of the class constants on \EventEspresso\core\libraries\form_sections\form_handlers\Form',
435
+						'event_espresso'
436
+					),
437
+					$form_config
438
+				)
439
+			);
440
+		}
441
+		$this->form_config = $form_config;
442
+	}
443
+
444
+
445
+	/**
446
+	 * called after the form is instantiated
447
+	 * and used for performing any logic that needs to occur early
448
+	 * before any of the other methods are called.
449
+	 * returns true if everything is ok to proceed,
450
+	 * and false if no further form logic should be implemented
451
+	 *
452
+	 * @return boolean
453
+	 */
454
+	public function initialize()
455
+	{
456
+		$this->form_has_errors = EE_Error::has_error(true);
457
+		return true;
458
+	}
459
+
460
+
461
+	/**
462
+	 * used for setting up css and js
463
+	 *
464
+	 * @return void
465
+	 * @throws LogicException
466
+	 * @throws EE_Error
467
+	 */
468
+	public function enqueueStylesAndScripts()
469
+	{
470
+		$this->form()->enqueue_js();
471
+	}
472
+
473
+
474
+	/**
475
+	 * creates and returns the actual form
476
+	 *
477
+	 * @return EE_Form_Section_Proper
478
+	 */
479
+	abstract public function generate();
480
+
481
+
482
+	/**
483
+	 * creates and returns an EE_Submit_Input labeled "Submit"
484
+	 *
485
+	 * @param string $text
486
+	 * @return EE_Submit_Input
487
+	 */
488
+	public function generateSubmitButton($text = '')
489
+	{
490
+		$text = ! empty($text) ? $text : $this->submitBtnText();
491
+		return new EE_Submit_Input(
492
+			array(
493
+				'html_name'             => 'ee-form-submit-' . $this->slug(),
494
+				'html_id'               => 'ee-form-submit-' . $this->slug(),
495
+				'html_class'            => 'ee-form-submit',
496
+				'html_label'            => '&nbsp;',
497
+				'other_html_attributes' => ' rel="' . $this->slug() . '"',
498
+				'default'               => $text,
499
+			)
500
+		);
501
+	}
502
+
503
+
504
+	/**
505
+	 * calls generateSubmitButton() and appends it onto the form along with a float clearing div
506
+	 *
507
+	 * @param string $text
508
+	 * @return void
509
+	 * @throws EE_Error
510
+	 */
511
+	public function appendSubmitButton($text = '')
512
+	{
513
+		if ($this->form->subsection_exists($this->slug() . '-submit-btn')) {
514
+			return;
515
+		}
516
+		$this->form->add_subsections(
517
+			array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)),
518
+			null,
519
+			false
520
+		);
521
+	}
522
+
523
+
524
+	/**
525
+	 * creates and returns an EE_Submit_Input labeled "Cancel"
526
+	 *
527
+	 * @param string $text
528
+	 * @return EE_Submit_Input
529
+	 */
530
+	public function generateCancelButton($text = '')
531
+	{
532
+		$cancel_button = new EE_Submit_Input(
533
+			array(
534
+				'html_name'             => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!!
535
+				'html_id'               => 'ee-cancel-form-' . $this->slug(),
536
+				'html_class'            => 'ee-cancel-form',
537
+				'html_label'            => '&nbsp;',
538
+				'other_html_attributes' => ' rel="' . $this->slug() . '"',
539
+				'default'               => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'),
540
+			)
541
+		);
542
+		$cancel_button->set_button_css_attributes(false);
543
+		return $cancel_button;
544
+	}
545
+
546
+
547
+	/**
548
+	 * appends a float clearing div onto end of form
549
+	 *
550
+	 * @return void
551
+	 * @throws EE_Error
552
+	 */
553
+	public function clearFormButtonFloats()
554
+	{
555
+		$this->form->add_subsections(
556
+			array(
557
+				'clear-submit-btn-float' => new EE_Form_Section_HTML(
558
+					EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx()
559
+				),
560
+			),
561
+			null,
562
+			false
563
+		);
564
+	}
565
+
566
+
567
+	/**
568
+	 * takes the generated form and displays it along with ony other non-form HTML that may be required
569
+	 * returns a string of HTML that can be directly echoed in a template
570
+	 *
571
+	 * @return string
572
+	 * @throws \InvalidArgumentException
573
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
574
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
575
+	 * @throws LogicException
576
+	 * @throws EE_Error
577
+	 */
578
+	public function display()
579
+	{
580
+		$form_html = apply_filters(
581
+			'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__before_form',
582
+			''
583
+		);
584
+		$form_config = $this->formConfig();
585
+		if ($form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
586
+			|| $form_config === FormHandler::ADD_FORM_TAGS_ONLY
587
+		) {
588
+			$form_html .= $this->form()->form_open($this->formAction());
589
+		}
590
+		$form_html .= $this->form(true)->get_html($this->form_has_errors);
591
+		if ($form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
592
+			|| $form_config === FormHandler::ADD_FORM_TAGS_ONLY
593
+		) {
594
+			$form_html .= $this->form()->form_close();
595
+		}
596
+		$form_html .= apply_filters(
597
+			'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__after_form',
598
+			''
599
+		);
600
+		return $form_html;
601
+	}
602
+
603
+
604
+	/**
605
+	 * handles processing the form submission
606
+	 * returns true or false depending on whether the form was processed successfully or not
607
+	 *
608
+	 * @param array $submitted_form_data
609
+	 * @return array
610
+	 * @throws \InvalidArgumentException
611
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
612
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
613
+	 * @throws EE_Error
614
+	 * @throws LogicException
615
+	 * @throws InvalidFormSubmissionException
616
+	 */
617
+	public function process($submitted_form_data = array())
618
+	{
619
+		if (! $this->form()->was_submitted($submitted_form_data)) {
620
+			throw new InvalidFormSubmissionException($this->form_name);
621
+		}
622
+		$this->form(true)->receive_form_submission($submitted_form_data);
623
+		if (! $this->form()->is_valid()) {
624
+			throw new InvalidFormSubmissionException(
625
+				$this->form_name,
626
+				sprintf(
627
+					esc_html__(
628
+						'The "%1$s" form is invalid. Please correct the following errors and resubmit: %2$s %3$s',
629
+						'event_espresso'
630
+					),
631
+					$this->form_name,
632
+					'<br />',
633
+					implode('<br />', $this->form()->get_validation_errors_accumulated())
634
+				)
635
+			);
636
+		}
637
+		return apply_filters(
638
+			'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__process__valid_data',
639
+			$this->form()->valid_data(),
640
+			$this
641
+		);
642
+	}
643 643
 }
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
      */
171 171
     public function form($for_display = false)
172 172
     {
173
-        if (! $this->formIsValid()) {
173
+        if ( ! $this->formIsValid()) {
174 174
             return null;
175 175
         }
176 176
         if ($for_display) {
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
      */
273 273
     public function setFormName($form_name)
274 274
     {
275
-        if (! is_string($form_name)) {
275
+        if ( ! is_string($form_name)) {
276 276
             throw new InvalidDataTypeException('$form_name', $form_name, 'string');
277 277
         }
278 278
         $this->form_name = $form_name;
@@ -296,7 +296,7 @@  discard block
 block discarded – undo
296 296
      */
297 297
     public function setAdminName($admin_name)
298 298
     {
299
-        if (! is_string($admin_name)) {
299
+        if ( ! is_string($admin_name)) {
300 300
             throw new InvalidDataTypeException('$admin_name', $admin_name, 'string');
301 301
         }
302 302
         $this->admin_name = $admin_name;
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
      */
321 321
     public function setSlug($slug)
322 322
     {
323
-        if (! is_string($slug)) {
323
+        if ( ! is_string($slug)) {
324 324
             throw new InvalidDataTypeException('$slug', $slug, 'string');
325 325
         }
326 326
         $this->slug = $slug;
@@ -343,7 +343,7 @@  discard block
 block discarded – undo
343 343
      */
344 344
     public function setSubmitBtnText($submit_btn_text)
345 345
     {
346
-        if (! is_string($submit_btn_text)) {
346
+        if ( ! is_string($submit_btn_text)) {
347 347
             throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string');
348 348
         }
349 349
         if (empty($submit_btn_text)) {
@@ -372,7 +372,7 @@  discard block
 block discarded – undo
372 372
      */
373 373
     public function setFormAction($form_action)
374 374
     {
375
-        if (! is_string($form_action)) {
375
+        if ( ! is_string($form_action)) {
376 376
             throw new InvalidDataTypeException('$form_action', $form_action, 'string');
377 377
         }
378 378
         $this->form_action = $form_action;
@@ -417,7 +417,7 @@  discard block
 block discarded – undo
417 417
      */
418 418
     public function setFormConfig($form_config)
419 419
     {
420
-        if (! in_array(
420
+        if ( ! in_array(
421 421
             $form_config,
422 422
             array(
423 423
                 FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
@@ -490,11 +490,11 @@  discard block
 block discarded – undo
490 490
         $text = ! empty($text) ? $text : $this->submitBtnText();
491 491
         return new EE_Submit_Input(
492 492
             array(
493
-                'html_name'             => 'ee-form-submit-' . $this->slug(),
494
-                'html_id'               => 'ee-form-submit-' . $this->slug(),
493
+                'html_name'             => 'ee-form-submit-'.$this->slug(),
494
+                'html_id'               => 'ee-form-submit-'.$this->slug(),
495 495
                 'html_class'            => 'ee-form-submit',
496 496
                 'html_label'            => '&nbsp;',
497
-                'other_html_attributes' => ' rel="' . $this->slug() . '"',
497
+                'other_html_attributes' => ' rel="'.$this->slug().'"',
498 498
                 'default'               => $text,
499 499
             )
500 500
         );
@@ -510,11 +510,11 @@  discard block
 block discarded – undo
510 510
      */
511 511
     public function appendSubmitButton($text = '')
512 512
     {
513
-        if ($this->form->subsection_exists($this->slug() . '-submit-btn')) {
513
+        if ($this->form->subsection_exists($this->slug().'-submit-btn')) {
514 514
             return;
515 515
         }
516 516
         $this->form->add_subsections(
517
-            array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)),
517
+            array($this->slug().'-submit-btn' => $this->generateSubmitButton($text)),
518 518
             null,
519 519
             false
520 520
         );
@@ -531,11 +531,11 @@  discard block
 block discarded – undo
531 531
     {
532 532
         $cancel_button = new EE_Submit_Input(
533 533
             array(
534
-                'html_name'             => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!!
535
-                'html_id'               => 'ee-cancel-form-' . $this->slug(),
534
+                'html_name'             => 'ee-form-submit-'.$this->slug(), // YES! Same name as submit !!!
535
+                'html_id'               => 'ee-cancel-form-'.$this->slug(),
536 536
                 'html_class'            => 'ee-cancel-form',
537 537
                 'html_label'            => '&nbsp;',
538
-                'other_html_attributes' => ' rel="' . $this->slug() . '"',
538
+                'other_html_attributes' => ' rel="'.$this->slug().'"',
539 539
                 'default'               => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'),
540 540
             )
541 541
         );
@@ -555,7 +555,7 @@  discard block
 block discarded – undo
555 555
         $this->form->add_subsections(
556 556
             array(
557 557
                 'clear-submit-btn-float' => new EE_Form_Section_HTML(
558
-                    EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx()
558
+                    EEH_HTML::div('', '', 'clear-float').EEH_HTML::divx()
559 559
                 ),
560 560
             ),
561 561
             null,
@@ -616,11 +616,11 @@  discard block
 block discarded – undo
616 616
      */
617 617
     public function process($submitted_form_data = array())
618 618
     {
619
-        if (! $this->form()->was_submitted($submitted_form_data)) {
619
+        if ( ! $this->form()->was_submitted($submitted_form_data)) {
620 620
             throw new InvalidFormSubmissionException($this->form_name);
621 621
         }
622 622
         $this->form(true)->receive_form_submission($submitted_form_data);
623
-        if (! $this->form()->is_valid()) {
623
+        if ( ! $this->form()->is_valid()) {
624 624
             throw new InvalidFormSubmissionException(
625 625
                 $this->form_name,
626 626
                 sprintf(
Please login to merge, or discard this patch.
core/libraries/form_sections/form_handlers/SequentialStepFormManager.php 2 patches
Indentation   +583 added lines, -583 removed lines patch added patch discarded remove patch
@@ -29,587 +29,587 @@
 block discarded – undo
29 29
 abstract class SequentialStepFormManager
30 30
 {
31 31
 
32
-    /**
33
-     * a simplified URL with no form related parameters
34
-     * that will be used to build the form's redirect URLs
35
-     *
36
-     * @var string $base_url
37
-     */
38
-    private $base_url = '';
39
-
40
-    /**
41
-     * the key used for the URL param that denotes the current form step
42
-     * defaults to 'ee-form-step'
43
-     *
44
-     * @var string $form_step_url_key
45
-     */
46
-    private $form_step_url_key = '';
47
-
48
-    /**
49
-     * @var string $default_form_step
50
-     */
51
-    private $default_form_step = '';
52
-
53
-    /**
54
-     * @var string $form_action
55
-     */
56
-    private $form_action;
57
-
58
-    /**
59
-     * value of one of the string constant above
60
-     *
61
-     * @var string $form_config
62
-     */
63
-    private $form_config;
64
-
65
-    /**
66
-     * @var string $progress_step_style
67
-     */
68
-    private $progress_step_style = '';
69
-
70
-    /**
71
-     * @var EE_Request $request
72
-     */
73
-    private $request;
74
-
75
-    /**
76
-     * @var Collection $form_steps
77
-     */
78
-    protected $form_steps;
79
-
80
-    /**
81
-     * @var ProgressStepManager $progress_step_manager
82
-     */
83
-    protected $progress_step_manager;
84
-
85
-
86
-    /**
87
-     * @return Collection|null
88
-     */
89
-    abstract protected function getFormStepsCollection();
90
-
91
-    // phpcs:disable PEAR.Functions.ValidDefaultValue.NotAtEnd
92
-    /**
93
-     * StepsManager constructor
94
-     *
95
-     * @param string     $base_url
96
-     * @param string     $default_form_step
97
-     * @param string     $form_action
98
-     * @param string     $form_config
99
-     * @param EE_Request $request
100
-     * @param string     $progress_step_style
101
-     * @throws InvalidDataTypeException
102
-     * @throws InvalidArgumentException
103
-     */
104
-    public function __construct(
105
-        $base_url,
106
-        $default_form_step,
107
-        $form_action = '',
108
-        $form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
109
-        $progress_step_style = 'number_bubbles',
110
-        EE_Request $request
111
-    ) {
112
-        $this->setBaseUrl($base_url);
113
-        $this->setDefaultFormStep($default_form_step);
114
-        $this->setFormAction($form_action);
115
-        $this->setFormConfig($form_config);
116
-        $this->setProgressStepStyle($progress_step_style);
117
-        $this->request = $request;
118
-    }
119
-
120
-
121
-    /**
122
-     * @return string
123
-     * @throws InvalidFormHandlerException
124
-     */
125
-    public function baseUrl()
126
-    {
127
-        if (strpos($this->base_url, $this->getCurrentStep()->slug()) === false) {
128
-            add_query_arg(
129
-                array($this->form_step_url_key => $this->getCurrentStep()->slug()),
130
-                $this->base_url
131
-            );
132
-        }
133
-        return $this->base_url;
134
-    }
135
-
136
-
137
-    /**
138
-     * @param string $base_url
139
-     * @throws InvalidDataTypeException
140
-     * @throws InvalidArgumentException
141
-     */
142
-    protected function setBaseUrl($base_url)
143
-    {
144
-        if (! is_string($base_url)) {
145
-            throw new InvalidDataTypeException('$base_url', $base_url, 'string');
146
-        }
147
-        if (empty($base_url)) {
148
-            throw new InvalidArgumentException(
149
-                esc_html__('The base URL can not be an empty string.', 'event_espresso')
150
-            );
151
-        }
152
-        $this->base_url = $base_url;
153
-    }
154
-
155
-
156
-    /**
157
-     * @return string
158
-     * @throws InvalidDataTypeException
159
-     */
160
-    public function formStepUrlKey()
161
-    {
162
-        if (empty($this->form_step_url_key)) {
163
-            $this->setFormStepUrlKey();
164
-        }
165
-        return $this->form_step_url_key;
166
-    }
167
-
168
-
169
-    /**
170
-     * @param string $form_step_url_key
171
-     * @throws InvalidDataTypeException
172
-     */
173
-    public function setFormStepUrlKey($form_step_url_key = 'ee-form-step')
174
-    {
175
-        if (! is_string($form_step_url_key)) {
176
-            throw new InvalidDataTypeException('$form_step_key', $form_step_url_key, 'string');
177
-        }
178
-        $this->form_step_url_key = ! empty($form_step_url_key) ? $form_step_url_key : 'ee-form-step';
179
-    }
180
-
181
-
182
-    /**
183
-     * @return string
184
-     */
185
-    public function defaultFormStep()
186
-    {
187
-        return $this->default_form_step;
188
-    }
189
-
190
-
191
-    /**
192
-     * @param $default_form_step
193
-     * @throws InvalidDataTypeException
194
-     */
195
-    protected function setDefaultFormStep($default_form_step)
196
-    {
197
-        if (! is_string($default_form_step)) {
198
-            throw new InvalidDataTypeException('$default_form_step', $default_form_step, 'string');
199
-        }
200
-        $this->default_form_step = $default_form_step;
201
-    }
202
-
203
-
204
-    /**
205
-     * @return void
206
-     * @throws \EventEspresso\core\exceptions\InvalidIdentifierException
207
-     * @throws InvalidDataTypeException
208
-     */
209
-    protected function setCurrentStepFromRequest()
210
-    {
211
-        $current_step_slug = $this->request()->get($this->formStepUrlKey(), $this->defaultFormStep());
212
-        if (! $this->form_steps->setCurrent($current_step_slug)) {
213
-            throw new InvalidIdentifierException(
214
-                $current_step_slug,
215
-                $this->defaultFormStep(),
216
-                $message = sprintf(
217
-                    esc_html__(
218
-                        'The "%1$s" form step could not be set.',
219
-                        'event_espresso'
220
-                    ),
221
-                    $current_step_slug
222
-                )
223
-            );
224
-        }
225
-    }
226
-
227
-
228
-    /**
229
-     * @return object|SequentialStepFormInterface
230
-     * @throws InvalidFormHandlerException
231
-     */
232
-    public function getCurrentStep()
233
-    {
234
-        if (! $this->form_steps->current() instanceof SequentialStepForm) {
235
-            throw new InvalidFormHandlerException($this->form_steps->current());
236
-        }
237
-        return $this->form_steps->current();
238
-    }
239
-
240
-
241
-    /**
242
-     * @return string
243
-     * @throws InvalidFormHandlerException
244
-     */
245
-    public function formAction()
246
-    {
247
-        if (! is_string($this->form_action) || empty($this->form_action)) {
248
-            $this->form_action = $this->baseUrl();
249
-        }
250
-        return $this->form_action;
251
-    }
252
-
253
-
254
-    /**
255
-     * @param string $form_action
256
-     * @throws InvalidDataTypeException
257
-     */
258
-    public function setFormAction($form_action)
259
-    {
260
-        if (! is_string($form_action)) {
261
-            throw new InvalidDataTypeException('$form_action', $form_action, 'string');
262
-        }
263
-        $this->form_action = $form_action;
264
-    }
265
-
266
-
267
-    /**
268
-     * @param array $form_action_args
269
-     * @throws InvalidDataTypeException
270
-     * @throws InvalidFormHandlerException
271
-     */
272
-    public function addFormActionArgs($form_action_args = array())
273
-    {
274
-        if (! is_array($form_action_args)) {
275
-            throw new InvalidDataTypeException('$form_action_args', $form_action_args, 'array');
276
-        }
277
-        $form_action_args = ! empty($form_action_args)
278
-            ? $form_action_args
279
-            : array($this->formStepUrlKey() => $this->form_steps->current()->slug());
280
-        $this->getCurrentStep()->setFormAction(
281
-            add_query_arg($form_action_args, $this->formAction())
282
-        );
283
-        $this->form_action = $this->getCurrentStep()->formAction();
284
-    }
285
-
286
-
287
-    /**
288
-     * @return string
289
-     */
290
-    public function formConfig()
291
-    {
292
-        return $this->form_config;
293
-    }
294
-
295
-
296
-    /**
297
-     * @param string $form_config
298
-     */
299
-    public function setFormConfig($form_config)
300
-    {
301
-        $this->form_config = $form_config;
302
-    }
303
-
304
-
305
-    /**
306
-     * @return string
307
-     */
308
-    public function progressStepStyle()
309
-    {
310
-        return $this->progress_step_style;
311
-    }
312
-
313
-
314
-    /**
315
-     * @param string $progress_step_style
316
-     */
317
-    public function setProgressStepStyle($progress_step_style)
318
-    {
319
-        $this->progress_step_style = $progress_step_style;
320
-    }
321
-
322
-
323
-    /**
324
-     * @return EE_Request
325
-     */
326
-    public function request()
327
-    {
328
-        return $this->request;
329
-    }
330
-
331
-
332
-    /**
333
-     * @return Collection|null
334
-     * @throws InvalidInterfaceException
335
-     */
336
-    protected function getProgressStepsCollection()
337
-    {
338
-        static $collection = null;
339
-        if (! $collection instanceof ProgressStepCollection) {
340
-            $collection = new ProgressStepCollection();
341
-        }
342
-        return $collection;
343
-    }
344
-
345
-
346
-    /**
347
-     * @param Collection $progress_steps_collection
348
-     * @return ProgressStepManager
349
-     * @throws InvalidInterfaceException
350
-     * @throws InvalidClassException
351
-     * @throws InvalidDataTypeException
352
-     * @throws InvalidEntityException
353
-     * @throws InvalidFormHandlerException
354
-     */
355
-    protected function generateProgressSteps(Collection $progress_steps_collection)
356
-    {
357
-        $current_step = $this->getCurrentStep();
358
-        /** @var SequentialStepForm $form_step */
359
-        foreach ($this->form_steps as $form_step) {
360
-            // is this step active ?
361
-            if (! $form_step->initialize()) {
362
-                continue;
363
-            }
364
-            $progress_steps_collection->add(
365
-                new ProgressStep(
366
-                    $form_step->order(),
367
-                    $form_step->slug(),
368
-                    $form_step->slug(),
369
-                    $form_step->formName()
370
-                ),
371
-                $form_step->slug()
372
-            );
373
-        }
374
-        // set collection pointer back to current step
375
-        $this->form_steps->setCurrentUsingObject($current_step);
376
-        return new ProgressStepManager(
377
-            $this->progressStepStyle(),
378
-            $this->defaultFormStep(),
379
-            $this->formStepUrlKey(),
380
-            $progress_steps_collection
381
-        );
382
-    }
383
-
384
-
385
-    /**
386
-     * @throws InvalidClassException
387
-     * @throws InvalidDataTypeException
388
-     * @throws InvalidEntityException
389
-     * @throws InvalidIdentifierException
390
-     * @throws InvalidInterfaceException
391
-     * @throws InvalidArgumentException
392
-     * @throws InvalidFormHandlerException
393
-     */
394
-    public function buildForm()
395
-    {
396
-        $this->buildCurrentStepFormForDisplay();
397
-    }
398
-
399
-
400
-    /**
401
-     * @param array $form_data
402
-     * @throws InvalidArgumentException
403
-     * @throws InvalidClassException
404
-     * @throws InvalidDataTypeException
405
-     * @throws InvalidEntityException
406
-     * @throws InvalidFormHandlerException
407
-     * @throws InvalidIdentifierException
408
-     * @throws InvalidInterfaceException
409
-     */
410
-    public function processForm($form_data = array())
411
-    {
412
-        $this->buildCurrentStepFormForProcessing();
413
-        $this->processCurrentStepForm($form_data);
414
-    }
415
-
416
-
417
-    /**
418
-     * @throws InvalidClassException
419
-     * @throws InvalidDataTypeException
420
-     * @throws InvalidEntityException
421
-     * @throws InvalidInterfaceException
422
-     * @throws InvalidIdentifierException
423
-     * @throws InvalidArgumentException
424
-     * @throws InvalidFormHandlerException
425
-     */
426
-    public function buildCurrentStepFormForDisplay()
427
-    {
428
-        $form_step = $this->buildCurrentStepForm();
429
-        // no displayable content ? then skip straight to processing
430
-        if (! $form_step->displayable()) {
431
-            $this->addFormActionArgs();
432
-            $form_step->setFormAction($this->formAction());
433
-            wp_safe_redirect($form_step->formAction());
434
-        }
435
-    }
436
-
437
-
438
-    /**
439
-     * @throws InvalidClassException
440
-     * @throws InvalidDataTypeException
441
-     * @throws InvalidEntityException
442
-     * @throws InvalidInterfaceException
443
-     * @throws InvalidIdentifierException
444
-     * @throws InvalidArgumentException
445
-     * @throws InvalidFormHandlerException
446
-     */
447
-    public function buildCurrentStepFormForProcessing()
448
-    {
449
-        $this->buildCurrentStepForm(false);
450
-    }
451
-
452
-
453
-    /**
454
-     * @param bool $for_display
455
-     * @return SequentialStepFormInterface
456
-     * @throws InvalidArgumentException
457
-     * @throws InvalidClassException
458
-     * @throws InvalidDataTypeException
459
-     * @throws InvalidEntityException
460
-     * @throws InvalidFormHandlerException
461
-     * @throws InvalidIdentifierException
462
-     * @throws InvalidInterfaceException
463
-     */
464
-    private function buildCurrentStepForm($for_display = true)
465
-    {
466
-        $this->form_steps = $this->getFormStepsCollection();
467
-        $this->setCurrentStepFromRequest();
468
-        $form_step = $this->getCurrentStep();
469
-        if ($form_step->submitBtnText() === esc_html__('Submit', 'event_espresso')) {
470
-            $form_step->setSubmitBtnText(esc_html__('Next Step', 'event_espresso'));
471
-        }
472
-        if ($for_display && $form_step->displayable()) {
473
-            $this->progress_step_manager = $this->generateProgressSteps(
474
-                $this->getProgressStepsCollection()
475
-            );
476
-            $this->progress_step_manager->setCurrentStep(
477
-                $form_step->slug()
478
-            );
479
-            // mark all previous progress steps as completed
480
-            $this->progress_step_manager->setPreviousStepsCompleted();
481
-            $this->progress_step_manager->enqueueStylesAndScripts();
482
-            $this->addFormActionArgs();
483
-            $form_step->setFormAction($this->formAction());
484
-        } else {
485
-            $form_step->setRedirectUrl($this->baseUrl());
486
-            $form_step->addRedirectArgs(
487
-                array($this->formStepUrlKey() => $this->form_steps->current()->slug())
488
-            );
489
-        }
490
-        $form_step->generate();
491
-        if ($for_display) {
492
-            $form_step->enqueueStylesAndScripts();
493
-        }
494
-        return $form_step;
495
-    }
496
-
497
-
498
-    /**
499
-     * @param bool $return_as_string
500
-     * @return string
501
-     * @throws InvalidFormHandlerException
502
-     */
503
-    public function displayProgressSteps($return_as_string = true)
504
-    {
505
-        $form_step = $this->getCurrentStep();
506
-        if (! $form_step->displayable()) {
507
-            return '';
508
-        }
509
-        $progress_steps = apply_filters(
510
-            'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_SequentialStepFormManager__displayProgressSteps__before_steps',
511
-            ''
512
-        );
513
-        $progress_steps .= $this->progress_step_manager->displaySteps();
514
-        $progress_steps .= apply_filters(
515
-            'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_SequentialStepFormManager__displayProgressSteps__after_steps',
516
-            ''
517
-        );
518
-        if ($return_as_string) {
519
-            return $progress_steps;
520
-        }
521
-        echo $progress_steps;
522
-        return '';
523
-    }
524
-
525
-
526
-    /**
527
-     * @param bool $return_as_string
528
-     * @return string
529
-     * @throws InvalidFormHandlerException
530
-     */
531
-    public function displayCurrentStepForm($return_as_string = true)
532
-    {
533
-        if ($return_as_string) {
534
-            return $this->getCurrentStep()->display();
535
-        }
536
-        echo $this->getCurrentStep()->display();
537
-        return '';
538
-    }
539
-
540
-
541
-    /**
542
-     * @param array $form_data
543
-     * @return void
544
-     * @throws InvalidArgumentException
545
-     * @throws InvalidDataTypeException
546
-     * @throws InvalidFormHandlerException
547
-     */
548
-    public function processCurrentStepForm($form_data = array())
549
-    {
550
-        // grab instance of current step because after calling next() below,
551
-        // any calls to getCurrentStep() will return the "next" step because we advanced
552
-        $current_step = $this->getCurrentStep();
553
-        try {
554
-            // form processing should either throw exceptions or return true
555
-            $current_step->process($form_data);
556
-        } catch (Exception $e) {
557
-            // something went wrong, so...
558
-            // if WP_DEBUG === true, display the Exception and stack trace right now
559
-            new ExceptionStackTraceDisplay($e);
560
-            // else convert the Exception to an EE_Error
561
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
562
-            // prevent redirect to next step or other if exception was thrown
563
-            if ($current_step->redirectTo() === SequentialStepForm::REDIRECT_TO_NEXT_STEP
564
-                || $current_step->redirectTo() === SequentialStepForm::REDIRECT_TO_OTHER
565
-            ) {
566
-                $current_step->setRedirectTo(SequentialStepForm::REDIRECT_TO_CURRENT_STEP);
567
-            }
568
-        }
569
-        // save notices to a transient so that when we redirect back
570
-        // to the display portion for this step
571
-        // those notices can be displayed
572
-        EE_Error::get_notices(false, true);
573
-        $this->redirectForm($current_step);
574
-    }
575
-
576
-
577
-    /**
578
-     * handles where to go to next
579
-     *
580
-     * @param SequentialStepFormInterface $current_step
581
-     * @throws InvalidArgumentException
582
-     * @throws InvalidDataTypeException
583
-     * @throws InvalidFormHandlerException
584
-     */
585
-    public function redirectForm(SequentialStepFormInterface $current_step)
586
-    {
587
-        $redirect_step = $current_step;
588
-        switch ($current_step->redirectTo()) {
589
-            case SequentialStepForm::REDIRECT_TO_OTHER:
590
-                // going somewhere else, so just check out now
591
-                wp_safe_redirect($redirect_step->redirectUrl());
592
-                exit();
593
-                break;
594
-            case SequentialStepForm::REDIRECT_TO_PREV_STEP:
595
-                $redirect_step = $this->form_steps->previous();
596
-                break;
597
-            case SequentialStepForm::REDIRECT_TO_NEXT_STEP:
598
-                $this->form_steps->next();
599
-                if ($this->form_steps->valid()) {
600
-                    $redirect_step = $this->form_steps->current();
601
-                }
602
-                break;
603
-            case SequentialStepForm::REDIRECT_TO_CURRENT_STEP:
604
-            default:
605
-                // $redirect_step is already set
606
-        }
607
-        $current_step->setRedirectUrl($this->baseUrl());
608
-        $current_step->addRedirectArgs(
609
-            // use the slug for whatever step we are redirecting too
610
-            array($this->formStepUrlKey() => $redirect_step->slug())
611
-        );
612
-        wp_safe_redirect($current_step->redirectUrl());
613
-        exit();
614
-    }
32
+	/**
33
+	 * a simplified URL with no form related parameters
34
+	 * that will be used to build the form's redirect URLs
35
+	 *
36
+	 * @var string $base_url
37
+	 */
38
+	private $base_url = '';
39
+
40
+	/**
41
+	 * the key used for the URL param that denotes the current form step
42
+	 * defaults to 'ee-form-step'
43
+	 *
44
+	 * @var string $form_step_url_key
45
+	 */
46
+	private $form_step_url_key = '';
47
+
48
+	/**
49
+	 * @var string $default_form_step
50
+	 */
51
+	private $default_form_step = '';
52
+
53
+	/**
54
+	 * @var string $form_action
55
+	 */
56
+	private $form_action;
57
+
58
+	/**
59
+	 * value of one of the string constant above
60
+	 *
61
+	 * @var string $form_config
62
+	 */
63
+	private $form_config;
64
+
65
+	/**
66
+	 * @var string $progress_step_style
67
+	 */
68
+	private $progress_step_style = '';
69
+
70
+	/**
71
+	 * @var EE_Request $request
72
+	 */
73
+	private $request;
74
+
75
+	/**
76
+	 * @var Collection $form_steps
77
+	 */
78
+	protected $form_steps;
79
+
80
+	/**
81
+	 * @var ProgressStepManager $progress_step_manager
82
+	 */
83
+	protected $progress_step_manager;
84
+
85
+
86
+	/**
87
+	 * @return Collection|null
88
+	 */
89
+	abstract protected function getFormStepsCollection();
90
+
91
+	// phpcs:disable PEAR.Functions.ValidDefaultValue.NotAtEnd
92
+	/**
93
+	 * StepsManager constructor
94
+	 *
95
+	 * @param string     $base_url
96
+	 * @param string     $default_form_step
97
+	 * @param string     $form_action
98
+	 * @param string     $form_config
99
+	 * @param EE_Request $request
100
+	 * @param string     $progress_step_style
101
+	 * @throws InvalidDataTypeException
102
+	 * @throws InvalidArgumentException
103
+	 */
104
+	public function __construct(
105
+		$base_url,
106
+		$default_form_step,
107
+		$form_action = '',
108
+		$form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
109
+		$progress_step_style = 'number_bubbles',
110
+		EE_Request $request
111
+	) {
112
+		$this->setBaseUrl($base_url);
113
+		$this->setDefaultFormStep($default_form_step);
114
+		$this->setFormAction($form_action);
115
+		$this->setFormConfig($form_config);
116
+		$this->setProgressStepStyle($progress_step_style);
117
+		$this->request = $request;
118
+	}
119
+
120
+
121
+	/**
122
+	 * @return string
123
+	 * @throws InvalidFormHandlerException
124
+	 */
125
+	public function baseUrl()
126
+	{
127
+		if (strpos($this->base_url, $this->getCurrentStep()->slug()) === false) {
128
+			add_query_arg(
129
+				array($this->form_step_url_key => $this->getCurrentStep()->slug()),
130
+				$this->base_url
131
+			);
132
+		}
133
+		return $this->base_url;
134
+	}
135
+
136
+
137
+	/**
138
+	 * @param string $base_url
139
+	 * @throws InvalidDataTypeException
140
+	 * @throws InvalidArgumentException
141
+	 */
142
+	protected function setBaseUrl($base_url)
143
+	{
144
+		if (! is_string($base_url)) {
145
+			throw new InvalidDataTypeException('$base_url', $base_url, 'string');
146
+		}
147
+		if (empty($base_url)) {
148
+			throw new InvalidArgumentException(
149
+				esc_html__('The base URL can not be an empty string.', 'event_espresso')
150
+			);
151
+		}
152
+		$this->base_url = $base_url;
153
+	}
154
+
155
+
156
+	/**
157
+	 * @return string
158
+	 * @throws InvalidDataTypeException
159
+	 */
160
+	public function formStepUrlKey()
161
+	{
162
+		if (empty($this->form_step_url_key)) {
163
+			$this->setFormStepUrlKey();
164
+		}
165
+		return $this->form_step_url_key;
166
+	}
167
+
168
+
169
+	/**
170
+	 * @param string $form_step_url_key
171
+	 * @throws InvalidDataTypeException
172
+	 */
173
+	public function setFormStepUrlKey($form_step_url_key = 'ee-form-step')
174
+	{
175
+		if (! is_string($form_step_url_key)) {
176
+			throw new InvalidDataTypeException('$form_step_key', $form_step_url_key, 'string');
177
+		}
178
+		$this->form_step_url_key = ! empty($form_step_url_key) ? $form_step_url_key : 'ee-form-step';
179
+	}
180
+
181
+
182
+	/**
183
+	 * @return string
184
+	 */
185
+	public function defaultFormStep()
186
+	{
187
+		return $this->default_form_step;
188
+	}
189
+
190
+
191
+	/**
192
+	 * @param $default_form_step
193
+	 * @throws InvalidDataTypeException
194
+	 */
195
+	protected function setDefaultFormStep($default_form_step)
196
+	{
197
+		if (! is_string($default_form_step)) {
198
+			throw new InvalidDataTypeException('$default_form_step', $default_form_step, 'string');
199
+		}
200
+		$this->default_form_step = $default_form_step;
201
+	}
202
+
203
+
204
+	/**
205
+	 * @return void
206
+	 * @throws \EventEspresso\core\exceptions\InvalidIdentifierException
207
+	 * @throws InvalidDataTypeException
208
+	 */
209
+	protected function setCurrentStepFromRequest()
210
+	{
211
+		$current_step_slug = $this->request()->get($this->formStepUrlKey(), $this->defaultFormStep());
212
+		if (! $this->form_steps->setCurrent($current_step_slug)) {
213
+			throw new InvalidIdentifierException(
214
+				$current_step_slug,
215
+				$this->defaultFormStep(),
216
+				$message = sprintf(
217
+					esc_html__(
218
+						'The "%1$s" form step could not be set.',
219
+						'event_espresso'
220
+					),
221
+					$current_step_slug
222
+				)
223
+			);
224
+		}
225
+	}
226
+
227
+
228
+	/**
229
+	 * @return object|SequentialStepFormInterface
230
+	 * @throws InvalidFormHandlerException
231
+	 */
232
+	public function getCurrentStep()
233
+	{
234
+		if (! $this->form_steps->current() instanceof SequentialStepForm) {
235
+			throw new InvalidFormHandlerException($this->form_steps->current());
236
+		}
237
+		return $this->form_steps->current();
238
+	}
239
+
240
+
241
+	/**
242
+	 * @return string
243
+	 * @throws InvalidFormHandlerException
244
+	 */
245
+	public function formAction()
246
+	{
247
+		if (! is_string($this->form_action) || empty($this->form_action)) {
248
+			$this->form_action = $this->baseUrl();
249
+		}
250
+		return $this->form_action;
251
+	}
252
+
253
+
254
+	/**
255
+	 * @param string $form_action
256
+	 * @throws InvalidDataTypeException
257
+	 */
258
+	public function setFormAction($form_action)
259
+	{
260
+		if (! is_string($form_action)) {
261
+			throw new InvalidDataTypeException('$form_action', $form_action, 'string');
262
+		}
263
+		$this->form_action = $form_action;
264
+	}
265
+
266
+
267
+	/**
268
+	 * @param array $form_action_args
269
+	 * @throws InvalidDataTypeException
270
+	 * @throws InvalidFormHandlerException
271
+	 */
272
+	public function addFormActionArgs($form_action_args = array())
273
+	{
274
+		if (! is_array($form_action_args)) {
275
+			throw new InvalidDataTypeException('$form_action_args', $form_action_args, 'array');
276
+		}
277
+		$form_action_args = ! empty($form_action_args)
278
+			? $form_action_args
279
+			: array($this->formStepUrlKey() => $this->form_steps->current()->slug());
280
+		$this->getCurrentStep()->setFormAction(
281
+			add_query_arg($form_action_args, $this->formAction())
282
+		);
283
+		$this->form_action = $this->getCurrentStep()->formAction();
284
+	}
285
+
286
+
287
+	/**
288
+	 * @return string
289
+	 */
290
+	public function formConfig()
291
+	{
292
+		return $this->form_config;
293
+	}
294
+
295
+
296
+	/**
297
+	 * @param string $form_config
298
+	 */
299
+	public function setFormConfig($form_config)
300
+	{
301
+		$this->form_config = $form_config;
302
+	}
303
+
304
+
305
+	/**
306
+	 * @return string
307
+	 */
308
+	public function progressStepStyle()
309
+	{
310
+		return $this->progress_step_style;
311
+	}
312
+
313
+
314
+	/**
315
+	 * @param string $progress_step_style
316
+	 */
317
+	public function setProgressStepStyle($progress_step_style)
318
+	{
319
+		$this->progress_step_style = $progress_step_style;
320
+	}
321
+
322
+
323
+	/**
324
+	 * @return EE_Request
325
+	 */
326
+	public function request()
327
+	{
328
+		return $this->request;
329
+	}
330
+
331
+
332
+	/**
333
+	 * @return Collection|null
334
+	 * @throws InvalidInterfaceException
335
+	 */
336
+	protected function getProgressStepsCollection()
337
+	{
338
+		static $collection = null;
339
+		if (! $collection instanceof ProgressStepCollection) {
340
+			$collection = new ProgressStepCollection();
341
+		}
342
+		return $collection;
343
+	}
344
+
345
+
346
+	/**
347
+	 * @param Collection $progress_steps_collection
348
+	 * @return ProgressStepManager
349
+	 * @throws InvalidInterfaceException
350
+	 * @throws InvalidClassException
351
+	 * @throws InvalidDataTypeException
352
+	 * @throws InvalidEntityException
353
+	 * @throws InvalidFormHandlerException
354
+	 */
355
+	protected function generateProgressSteps(Collection $progress_steps_collection)
356
+	{
357
+		$current_step = $this->getCurrentStep();
358
+		/** @var SequentialStepForm $form_step */
359
+		foreach ($this->form_steps as $form_step) {
360
+			// is this step active ?
361
+			if (! $form_step->initialize()) {
362
+				continue;
363
+			}
364
+			$progress_steps_collection->add(
365
+				new ProgressStep(
366
+					$form_step->order(),
367
+					$form_step->slug(),
368
+					$form_step->slug(),
369
+					$form_step->formName()
370
+				),
371
+				$form_step->slug()
372
+			);
373
+		}
374
+		// set collection pointer back to current step
375
+		$this->form_steps->setCurrentUsingObject($current_step);
376
+		return new ProgressStepManager(
377
+			$this->progressStepStyle(),
378
+			$this->defaultFormStep(),
379
+			$this->formStepUrlKey(),
380
+			$progress_steps_collection
381
+		);
382
+	}
383
+
384
+
385
+	/**
386
+	 * @throws InvalidClassException
387
+	 * @throws InvalidDataTypeException
388
+	 * @throws InvalidEntityException
389
+	 * @throws InvalidIdentifierException
390
+	 * @throws InvalidInterfaceException
391
+	 * @throws InvalidArgumentException
392
+	 * @throws InvalidFormHandlerException
393
+	 */
394
+	public function buildForm()
395
+	{
396
+		$this->buildCurrentStepFormForDisplay();
397
+	}
398
+
399
+
400
+	/**
401
+	 * @param array $form_data
402
+	 * @throws InvalidArgumentException
403
+	 * @throws InvalidClassException
404
+	 * @throws InvalidDataTypeException
405
+	 * @throws InvalidEntityException
406
+	 * @throws InvalidFormHandlerException
407
+	 * @throws InvalidIdentifierException
408
+	 * @throws InvalidInterfaceException
409
+	 */
410
+	public function processForm($form_data = array())
411
+	{
412
+		$this->buildCurrentStepFormForProcessing();
413
+		$this->processCurrentStepForm($form_data);
414
+	}
415
+
416
+
417
+	/**
418
+	 * @throws InvalidClassException
419
+	 * @throws InvalidDataTypeException
420
+	 * @throws InvalidEntityException
421
+	 * @throws InvalidInterfaceException
422
+	 * @throws InvalidIdentifierException
423
+	 * @throws InvalidArgumentException
424
+	 * @throws InvalidFormHandlerException
425
+	 */
426
+	public function buildCurrentStepFormForDisplay()
427
+	{
428
+		$form_step = $this->buildCurrentStepForm();
429
+		// no displayable content ? then skip straight to processing
430
+		if (! $form_step->displayable()) {
431
+			$this->addFormActionArgs();
432
+			$form_step->setFormAction($this->formAction());
433
+			wp_safe_redirect($form_step->formAction());
434
+		}
435
+	}
436
+
437
+
438
+	/**
439
+	 * @throws InvalidClassException
440
+	 * @throws InvalidDataTypeException
441
+	 * @throws InvalidEntityException
442
+	 * @throws InvalidInterfaceException
443
+	 * @throws InvalidIdentifierException
444
+	 * @throws InvalidArgumentException
445
+	 * @throws InvalidFormHandlerException
446
+	 */
447
+	public function buildCurrentStepFormForProcessing()
448
+	{
449
+		$this->buildCurrentStepForm(false);
450
+	}
451
+
452
+
453
+	/**
454
+	 * @param bool $for_display
455
+	 * @return SequentialStepFormInterface
456
+	 * @throws InvalidArgumentException
457
+	 * @throws InvalidClassException
458
+	 * @throws InvalidDataTypeException
459
+	 * @throws InvalidEntityException
460
+	 * @throws InvalidFormHandlerException
461
+	 * @throws InvalidIdentifierException
462
+	 * @throws InvalidInterfaceException
463
+	 */
464
+	private function buildCurrentStepForm($for_display = true)
465
+	{
466
+		$this->form_steps = $this->getFormStepsCollection();
467
+		$this->setCurrentStepFromRequest();
468
+		$form_step = $this->getCurrentStep();
469
+		if ($form_step->submitBtnText() === esc_html__('Submit', 'event_espresso')) {
470
+			$form_step->setSubmitBtnText(esc_html__('Next Step', 'event_espresso'));
471
+		}
472
+		if ($for_display && $form_step->displayable()) {
473
+			$this->progress_step_manager = $this->generateProgressSteps(
474
+				$this->getProgressStepsCollection()
475
+			);
476
+			$this->progress_step_manager->setCurrentStep(
477
+				$form_step->slug()
478
+			);
479
+			// mark all previous progress steps as completed
480
+			$this->progress_step_manager->setPreviousStepsCompleted();
481
+			$this->progress_step_manager->enqueueStylesAndScripts();
482
+			$this->addFormActionArgs();
483
+			$form_step->setFormAction($this->formAction());
484
+		} else {
485
+			$form_step->setRedirectUrl($this->baseUrl());
486
+			$form_step->addRedirectArgs(
487
+				array($this->formStepUrlKey() => $this->form_steps->current()->slug())
488
+			);
489
+		}
490
+		$form_step->generate();
491
+		if ($for_display) {
492
+			$form_step->enqueueStylesAndScripts();
493
+		}
494
+		return $form_step;
495
+	}
496
+
497
+
498
+	/**
499
+	 * @param bool $return_as_string
500
+	 * @return string
501
+	 * @throws InvalidFormHandlerException
502
+	 */
503
+	public function displayProgressSteps($return_as_string = true)
504
+	{
505
+		$form_step = $this->getCurrentStep();
506
+		if (! $form_step->displayable()) {
507
+			return '';
508
+		}
509
+		$progress_steps = apply_filters(
510
+			'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_SequentialStepFormManager__displayProgressSteps__before_steps',
511
+			''
512
+		);
513
+		$progress_steps .= $this->progress_step_manager->displaySteps();
514
+		$progress_steps .= apply_filters(
515
+			'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_SequentialStepFormManager__displayProgressSteps__after_steps',
516
+			''
517
+		);
518
+		if ($return_as_string) {
519
+			return $progress_steps;
520
+		}
521
+		echo $progress_steps;
522
+		return '';
523
+	}
524
+
525
+
526
+	/**
527
+	 * @param bool $return_as_string
528
+	 * @return string
529
+	 * @throws InvalidFormHandlerException
530
+	 */
531
+	public function displayCurrentStepForm($return_as_string = true)
532
+	{
533
+		if ($return_as_string) {
534
+			return $this->getCurrentStep()->display();
535
+		}
536
+		echo $this->getCurrentStep()->display();
537
+		return '';
538
+	}
539
+
540
+
541
+	/**
542
+	 * @param array $form_data
543
+	 * @return void
544
+	 * @throws InvalidArgumentException
545
+	 * @throws InvalidDataTypeException
546
+	 * @throws InvalidFormHandlerException
547
+	 */
548
+	public function processCurrentStepForm($form_data = array())
549
+	{
550
+		// grab instance of current step because after calling next() below,
551
+		// any calls to getCurrentStep() will return the "next" step because we advanced
552
+		$current_step = $this->getCurrentStep();
553
+		try {
554
+			// form processing should either throw exceptions or return true
555
+			$current_step->process($form_data);
556
+		} catch (Exception $e) {
557
+			// something went wrong, so...
558
+			// if WP_DEBUG === true, display the Exception and stack trace right now
559
+			new ExceptionStackTraceDisplay($e);
560
+			// else convert the Exception to an EE_Error
561
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
562
+			// prevent redirect to next step or other if exception was thrown
563
+			if ($current_step->redirectTo() === SequentialStepForm::REDIRECT_TO_NEXT_STEP
564
+				|| $current_step->redirectTo() === SequentialStepForm::REDIRECT_TO_OTHER
565
+			) {
566
+				$current_step->setRedirectTo(SequentialStepForm::REDIRECT_TO_CURRENT_STEP);
567
+			}
568
+		}
569
+		// save notices to a transient so that when we redirect back
570
+		// to the display portion for this step
571
+		// those notices can be displayed
572
+		EE_Error::get_notices(false, true);
573
+		$this->redirectForm($current_step);
574
+	}
575
+
576
+
577
+	/**
578
+	 * handles where to go to next
579
+	 *
580
+	 * @param SequentialStepFormInterface $current_step
581
+	 * @throws InvalidArgumentException
582
+	 * @throws InvalidDataTypeException
583
+	 * @throws InvalidFormHandlerException
584
+	 */
585
+	public function redirectForm(SequentialStepFormInterface $current_step)
586
+	{
587
+		$redirect_step = $current_step;
588
+		switch ($current_step->redirectTo()) {
589
+			case SequentialStepForm::REDIRECT_TO_OTHER:
590
+				// going somewhere else, so just check out now
591
+				wp_safe_redirect($redirect_step->redirectUrl());
592
+				exit();
593
+				break;
594
+			case SequentialStepForm::REDIRECT_TO_PREV_STEP:
595
+				$redirect_step = $this->form_steps->previous();
596
+				break;
597
+			case SequentialStepForm::REDIRECT_TO_NEXT_STEP:
598
+				$this->form_steps->next();
599
+				if ($this->form_steps->valid()) {
600
+					$redirect_step = $this->form_steps->current();
601
+				}
602
+				break;
603
+			case SequentialStepForm::REDIRECT_TO_CURRENT_STEP:
604
+			default:
605
+				// $redirect_step is already set
606
+		}
607
+		$current_step->setRedirectUrl($this->baseUrl());
608
+		$current_step->addRedirectArgs(
609
+			// use the slug for whatever step we are redirecting too
610
+			array($this->formStepUrlKey() => $redirect_step->slug())
611
+		);
612
+		wp_safe_redirect($current_step->redirectUrl());
613
+		exit();
614
+	}
615 615
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
      */
142 142
     protected function setBaseUrl($base_url)
143 143
     {
144
-        if (! is_string($base_url)) {
144
+        if ( ! is_string($base_url)) {
145 145
             throw new InvalidDataTypeException('$base_url', $base_url, 'string');
146 146
         }
147 147
         if (empty($base_url)) {
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
      */
173 173
     public function setFormStepUrlKey($form_step_url_key = 'ee-form-step')
174 174
     {
175
-        if (! is_string($form_step_url_key)) {
175
+        if ( ! is_string($form_step_url_key)) {
176 176
             throw new InvalidDataTypeException('$form_step_key', $form_step_url_key, 'string');
177 177
         }
178 178
         $this->form_step_url_key = ! empty($form_step_url_key) ? $form_step_url_key : 'ee-form-step';
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
      */
195 195
     protected function setDefaultFormStep($default_form_step)
196 196
     {
197
-        if (! is_string($default_form_step)) {
197
+        if ( ! is_string($default_form_step)) {
198 198
             throw new InvalidDataTypeException('$default_form_step', $default_form_step, 'string');
199 199
         }
200 200
         $this->default_form_step = $default_form_step;
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
     protected function setCurrentStepFromRequest()
210 210
     {
211 211
         $current_step_slug = $this->request()->get($this->formStepUrlKey(), $this->defaultFormStep());
212
-        if (! $this->form_steps->setCurrent($current_step_slug)) {
212
+        if ( ! $this->form_steps->setCurrent($current_step_slug)) {
213 213
             throw new InvalidIdentifierException(
214 214
                 $current_step_slug,
215 215
                 $this->defaultFormStep(),
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
      */
232 232
     public function getCurrentStep()
233 233
     {
234
-        if (! $this->form_steps->current() instanceof SequentialStepForm) {
234
+        if ( ! $this->form_steps->current() instanceof SequentialStepForm) {
235 235
             throw new InvalidFormHandlerException($this->form_steps->current());
236 236
         }
237 237
         return $this->form_steps->current();
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
      */
245 245
     public function formAction()
246 246
     {
247
-        if (! is_string($this->form_action) || empty($this->form_action)) {
247
+        if ( ! is_string($this->form_action) || empty($this->form_action)) {
248 248
             $this->form_action = $this->baseUrl();
249 249
         }
250 250
         return $this->form_action;
@@ -257,7 +257,7 @@  discard block
 block discarded – undo
257 257
      */
258 258
     public function setFormAction($form_action)
259 259
     {
260
-        if (! is_string($form_action)) {
260
+        if ( ! is_string($form_action)) {
261 261
             throw new InvalidDataTypeException('$form_action', $form_action, 'string');
262 262
         }
263 263
         $this->form_action = $form_action;
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
      */
272 272
     public function addFormActionArgs($form_action_args = array())
273 273
     {
274
-        if (! is_array($form_action_args)) {
274
+        if ( ! is_array($form_action_args)) {
275 275
             throw new InvalidDataTypeException('$form_action_args', $form_action_args, 'array');
276 276
         }
277 277
         $form_action_args = ! empty($form_action_args)
@@ -336,7 +336,7 @@  discard block
 block discarded – undo
336 336
     protected function getProgressStepsCollection()
337 337
     {
338 338
         static $collection = null;
339
-        if (! $collection instanceof ProgressStepCollection) {
339
+        if ( ! $collection instanceof ProgressStepCollection) {
340 340
             $collection = new ProgressStepCollection();
341 341
         }
342 342
         return $collection;
@@ -358,7 +358,7 @@  discard block
 block discarded – undo
358 358
         /** @var SequentialStepForm $form_step */
359 359
         foreach ($this->form_steps as $form_step) {
360 360
             // is this step active ?
361
-            if (! $form_step->initialize()) {
361
+            if ( ! $form_step->initialize()) {
362 362
                 continue;
363 363
             }
364 364
             $progress_steps_collection->add(
@@ -427,7 +427,7 @@  discard block
 block discarded – undo
427 427
     {
428 428
         $form_step = $this->buildCurrentStepForm();
429 429
         // no displayable content ? then skip straight to processing
430
-        if (! $form_step->displayable()) {
430
+        if ( ! $form_step->displayable()) {
431 431
             $this->addFormActionArgs();
432 432
             $form_step->setFormAction($this->formAction());
433 433
             wp_safe_redirect($form_step->formAction());
@@ -503,7 +503,7 @@  discard block
 block discarded – undo
503 503
     public function displayProgressSteps($return_as_string = true)
504 504
     {
505 505
         $form_step = $this->getCurrentStep();
506
-        if (! $form_step->displayable()) {
506
+        if ( ! $form_step->displayable()) {
507 507
             return '';
508 508
         }
509 509
         $progress_steps = apply_filters(
Please login to merge, or discard this patch.
core/libraries/form_sections/form_handlers/InvalidFormHandlerException.php 1 patch
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -13,25 +13,25 @@
 block discarded – undo
13 13
 class InvalidFormHandlerException extends \UnexpectedValueException
14 14
 {
15 15
 
16
-    /**
17
-     * InvalidFormHandlerException constructor.
18
-     *
19
-     * @param string     $actual the FormHandler object that was received
20
-     * @param string     $message
21
-     * @param int        $code
22
-     * @param \Exception $previous
23
-     */
24
-    public function __construct($actual, $message = '', $code = 0, \Exception $previous = null)
25
-    {
26
-        if (empty($message)) {
27
-            $message = sprintf(
28
-                __(
29
-                    'A valid Form Handler was expected but instead "%1$s" was received.',
30
-                    'event_espresso'
31
-                ),
32
-                $actual
33
-            );
34
-        }
35
-        parent::__construct($message, $code, $previous);
36
-    }
16
+	/**
17
+	 * InvalidFormHandlerException constructor.
18
+	 *
19
+	 * @param string     $actual the FormHandler object that was received
20
+	 * @param string     $message
21
+	 * @param int        $code
22
+	 * @param \Exception $previous
23
+	 */
24
+	public function __construct($actual, $message = '', $code = 0, \Exception $previous = null)
25
+	{
26
+		if (empty($message)) {
27
+			$message = sprintf(
28
+				__(
29
+					'A valid Form Handler was expected but instead "%1$s" was received.',
30
+					'event_espresso'
31
+				),
32
+				$actual
33
+			);
34
+		}
35
+		parent::__construct($message, $code, $previous);
36
+	}
37 37
 }
Please login to merge, or discard this patch.
core/libraries/form_sections/strategies/filter/FormHtmlFilter.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -14,10 +14,10 @@
 block discarded – undo
14 14
 abstract class FormHtmlFilter
15 15
 {
16 16
 
17
-    /**
18
-     * @param                             $html
19
-     * @param EE_Form_Section_Validatable $form_section
20
-     * @return string
21
-     */
22
-    abstract public function filterHtml($html, EE_Form_Section_Validatable $form_section);
17
+	/**
18
+	 * @param                             $html
19
+	 * @param EE_Form_Section_Validatable $form_section
20
+	 * @return string
21
+	 */
22
+	abstract public function filterHtml($html, EE_Form_Section_Validatable $form_section);
23 23
 }
Please login to merge, or discard this patch.