@@ -16,48 +16,48 @@ |
||
16 | 16 | { |
17 | 17 | |
18 | 18 | |
19 | - /** |
|
20 | - * @var \EE_Registration $target_registration |
|
21 | - */ |
|
22 | - private $target_registration; |
|
23 | - |
|
24 | - |
|
25 | - /** |
|
26 | - * @var \EE_Registration $registration_to_copy |
|
27 | - */ |
|
28 | - private $registration_to_copy; |
|
29 | - |
|
30 | - |
|
31 | - /** |
|
32 | - * CopyRegistrationDetailsCommand constructor. |
|
33 | - * |
|
34 | - * @param \EE_Registration $target_registration |
|
35 | - * @param \EE_Registration $registration_to_copy |
|
36 | - * v |
|
37 | - */ |
|
38 | - public function __construct( |
|
39 | - \EE_Registration $target_registration, |
|
40 | - \EE_Registration $registration_to_copy |
|
41 | - ) { |
|
42 | - $this->target_registration = $target_registration; |
|
43 | - $this->registration_to_copy = $registration_to_copy; |
|
44 | - } |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * @return \EE_Registration |
|
49 | - */ |
|
50 | - public function targetRegistration() |
|
51 | - { |
|
52 | - return $this->target_registration; |
|
53 | - } |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - * @return \EE_Registration |
|
58 | - */ |
|
59 | - public function registrationToCopy() |
|
60 | - { |
|
61 | - return $this->registration_to_copy; |
|
62 | - } |
|
19 | + /** |
|
20 | + * @var \EE_Registration $target_registration |
|
21 | + */ |
|
22 | + private $target_registration; |
|
23 | + |
|
24 | + |
|
25 | + /** |
|
26 | + * @var \EE_Registration $registration_to_copy |
|
27 | + */ |
|
28 | + private $registration_to_copy; |
|
29 | + |
|
30 | + |
|
31 | + /** |
|
32 | + * CopyRegistrationDetailsCommand constructor. |
|
33 | + * |
|
34 | + * @param \EE_Registration $target_registration |
|
35 | + * @param \EE_Registration $registration_to_copy |
|
36 | + * v |
|
37 | + */ |
|
38 | + public function __construct( |
|
39 | + \EE_Registration $target_registration, |
|
40 | + \EE_Registration $registration_to_copy |
|
41 | + ) { |
|
42 | + $this->target_registration = $target_registration; |
|
43 | + $this->registration_to_copy = $registration_to_copy; |
|
44 | + } |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * @return \EE_Registration |
|
49 | + */ |
|
50 | + public function targetRegistration() |
|
51 | + { |
|
52 | + return $this->target_registration; |
|
53 | + } |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + * @return \EE_Registration |
|
58 | + */ |
|
59 | + public function registrationToCopy() |
|
60 | + { |
|
61 | + return $this->registration_to_copy; |
|
62 | + } |
|
63 | 63 | } |
@@ -24,151 +24,151 @@ |
||
24 | 24 | class CreateRegistrationCommand extends Command implements CommandRequiresCapCheckInterface |
25 | 25 | { |
26 | 26 | |
27 | - /** |
|
28 | - * @var EE_Transaction $transaction |
|
29 | - */ |
|
30 | - private $transaction; |
|
31 | - |
|
32 | - /** |
|
33 | - * @var EE_Ticket $ticket |
|
34 | - */ |
|
35 | - private $ticket; |
|
36 | - |
|
37 | - /** |
|
38 | - * @var EE_Line_Item $ticket_line_item |
|
39 | - */ |
|
40 | - private $ticket_line_item; |
|
41 | - |
|
42 | - /** |
|
43 | - * @var int $reg_count |
|
44 | - */ |
|
45 | - private $reg_count; |
|
46 | - |
|
47 | - /** |
|
48 | - * @var int $reg_group_size |
|
49 | - */ |
|
50 | - private $reg_group_size; |
|
51 | - |
|
52 | - /** |
|
53 | - * @var string $reg_status |
|
54 | - */ |
|
55 | - private $reg_status; |
|
56 | - |
|
57 | - /** |
|
58 | - * @var EE_Registration $registration |
|
59 | - */ |
|
60 | - protected $registration; |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * CreateRegistrationCommand constructor. |
|
65 | - * |
|
66 | - * @param EE_Transaction $transaction |
|
67 | - * @param EE_Line_Item $ticket_line_item |
|
68 | - * @param int $reg_count |
|
69 | - * @param int $reg_group_size |
|
70 | - * @param string $reg_status |
|
71 | - * @throws InvalidEntityException |
|
72 | - */ |
|
73 | - public function __construct( |
|
74 | - EE_Transaction $transaction, |
|
75 | - EE_Line_Item $ticket_line_item, |
|
76 | - $reg_count = 1, |
|
77 | - $reg_group_size = 0, |
|
78 | - $reg_status = EEM_Registration::status_id_incomplete |
|
79 | - ) { |
|
80 | - // grab the related ticket object for this line_item |
|
81 | - $this->ticket = $ticket_line_item->ticket(); |
|
82 | - if (! $this->ticket instanceof EE_Ticket) { |
|
83 | - throw new InvalidEntityException( |
|
84 | - is_object($this->ticket) ? get_class($this->ticket) : gettype($this->ticket), |
|
85 | - 'EE_Ticket', |
|
86 | - sprintf( |
|
87 | - __('Line item %s did not contain a valid ticket', 'event_espresso'), |
|
88 | - $ticket_line_item->ID() |
|
89 | - ) |
|
90 | - ); |
|
91 | - } |
|
92 | - $this->transaction = $transaction; |
|
93 | - $this->ticket_line_item = $ticket_line_item; |
|
94 | - $this->reg_count = absint($reg_count); |
|
95 | - $this->reg_group_size = absint($reg_group_size); |
|
96 | - $this->reg_status = $reg_status; |
|
97 | - } |
|
98 | - |
|
99 | - |
|
100 | - /** |
|
101 | - * @return \EventEspresso\core\domain\services\capabilities\CapCheckInterface |
|
102 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
103 | - */ |
|
104 | - public function getCapCheck() |
|
105 | - { |
|
106 | - if (! $this->cap_check instanceof CapCheckInterface) { |
|
107 | - return new CapCheck('ee_edit_registrations', 'create_new_registration'); |
|
108 | - } |
|
109 | - return $this->cap_check; |
|
110 | - } |
|
111 | - |
|
112 | - |
|
113 | - /** |
|
114 | - * @return EE_Transaction |
|
115 | - */ |
|
116 | - public function transaction() |
|
117 | - { |
|
118 | - return $this->transaction; |
|
119 | - } |
|
120 | - |
|
121 | - |
|
122 | - /** |
|
123 | - * @return EE_Ticket |
|
124 | - */ |
|
125 | - public function ticket() |
|
126 | - { |
|
127 | - return $this->ticket; |
|
128 | - } |
|
129 | - |
|
130 | - |
|
131 | - /** |
|
132 | - * @return EE_Line_Item |
|
133 | - */ |
|
134 | - public function ticketLineItem() |
|
135 | - { |
|
136 | - return $this->ticket_line_item; |
|
137 | - } |
|
138 | - |
|
139 | - |
|
140 | - /** |
|
141 | - * @return int |
|
142 | - */ |
|
143 | - public function regCount() |
|
144 | - { |
|
145 | - return $this->reg_count; |
|
146 | - } |
|
147 | - |
|
148 | - |
|
149 | - /** |
|
150 | - * @return int |
|
151 | - */ |
|
152 | - public function regGroupSize() |
|
153 | - { |
|
154 | - return $this->reg_group_size; |
|
155 | - } |
|
156 | - |
|
157 | - |
|
158 | - /** |
|
159 | - * @return string |
|
160 | - */ |
|
161 | - public function regStatus() |
|
162 | - { |
|
163 | - return $this->reg_status; |
|
164 | - } |
|
165 | - |
|
166 | - |
|
167 | - /** |
|
168 | - * @return EE_Registration |
|
169 | - */ |
|
170 | - public function registration() |
|
171 | - { |
|
172 | - return $this->registration; |
|
173 | - } |
|
27 | + /** |
|
28 | + * @var EE_Transaction $transaction |
|
29 | + */ |
|
30 | + private $transaction; |
|
31 | + |
|
32 | + /** |
|
33 | + * @var EE_Ticket $ticket |
|
34 | + */ |
|
35 | + private $ticket; |
|
36 | + |
|
37 | + /** |
|
38 | + * @var EE_Line_Item $ticket_line_item |
|
39 | + */ |
|
40 | + private $ticket_line_item; |
|
41 | + |
|
42 | + /** |
|
43 | + * @var int $reg_count |
|
44 | + */ |
|
45 | + private $reg_count; |
|
46 | + |
|
47 | + /** |
|
48 | + * @var int $reg_group_size |
|
49 | + */ |
|
50 | + private $reg_group_size; |
|
51 | + |
|
52 | + /** |
|
53 | + * @var string $reg_status |
|
54 | + */ |
|
55 | + private $reg_status; |
|
56 | + |
|
57 | + /** |
|
58 | + * @var EE_Registration $registration |
|
59 | + */ |
|
60 | + protected $registration; |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * CreateRegistrationCommand constructor. |
|
65 | + * |
|
66 | + * @param EE_Transaction $transaction |
|
67 | + * @param EE_Line_Item $ticket_line_item |
|
68 | + * @param int $reg_count |
|
69 | + * @param int $reg_group_size |
|
70 | + * @param string $reg_status |
|
71 | + * @throws InvalidEntityException |
|
72 | + */ |
|
73 | + public function __construct( |
|
74 | + EE_Transaction $transaction, |
|
75 | + EE_Line_Item $ticket_line_item, |
|
76 | + $reg_count = 1, |
|
77 | + $reg_group_size = 0, |
|
78 | + $reg_status = EEM_Registration::status_id_incomplete |
|
79 | + ) { |
|
80 | + // grab the related ticket object for this line_item |
|
81 | + $this->ticket = $ticket_line_item->ticket(); |
|
82 | + if (! $this->ticket instanceof EE_Ticket) { |
|
83 | + throw new InvalidEntityException( |
|
84 | + is_object($this->ticket) ? get_class($this->ticket) : gettype($this->ticket), |
|
85 | + 'EE_Ticket', |
|
86 | + sprintf( |
|
87 | + __('Line item %s did not contain a valid ticket', 'event_espresso'), |
|
88 | + $ticket_line_item->ID() |
|
89 | + ) |
|
90 | + ); |
|
91 | + } |
|
92 | + $this->transaction = $transaction; |
|
93 | + $this->ticket_line_item = $ticket_line_item; |
|
94 | + $this->reg_count = absint($reg_count); |
|
95 | + $this->reg_group_size = absint($reg_group_size); |
|
96 | + $this->reg_status = $reg_status; |
|
97 | + } |
|
98 | + |
|
99 | + |
|
100 | + /** |
|
101 | + * @return \EventEspresso\core\domain\services\capabilities\CapCheckInterface |
|
102 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
103 | + */ |
|
104 | + public function getCapCheck() |
|
105 | + { |
|
106 | + if (! $this->cap_check instanceof CapCheckInterface) { |
|
107 | + return new CapCheck('ee_edit_registrations', 'create_new_registration'); |
|
108 | + } |
|
109 | + return $this->cap_check; |
|
110 | + } |
|
111 | + |
|
112 | + |
|
113 | + /** |
|
114 | + * @return EE_Transaction |
|
115 | + */ |
|
116 | + public function transaction() |
|
117 | + { |
|
118 | + return $this->transaction; |
|
119 | + } |
|
120 | + |
|
121 | + |
|
122 | + /** |
|
123 | + * @return EE_Ticket |
|
124 | + */ |
|
125 | + public function ticket() |
|
126 | + { |
|
127 | + return $this->ticket; |
|
128 | + } |
|
129 | + |
|
130 | + |
|
131 | + /** |
|
132 | + * @return EE_Line_Item |
|
133 | + */ |
|
134 | + public function ticketLineItem() |
|
135 | + { |
|
136 | + return $this->ticket_line_item; |
|
137 | + } |
|
138 | + |
|
139 | + |
|
140 | + /** |
|
141 | + * @return int |
|
142 | + */ |
|
143 | + public function regCount() |
|
144 | + { |
|
145 | + return $this->reg_count; |
|
146 | + } |
|
147 | + |
|
148 | + |
|
149 | + /** |
|
150 | + * @return int |
|
151 | + */ |
|
152 | + public function regGroupSize() |
|
153 | + { |
|
154 | + return $this->reg_group_size; |
|
155 | + } |
|
156 | + |
|
157 | + |
|
158 | + /** |
|
159 | + * @return string |
|
160 | + */ |
|
161 | + public function regStatus() |
|
162 | + { |
|
163 | + return $this->reg_status; |
|
164 | + } |
|
165 | + |
|
166 | + |
|
167 | + /** |
|
168 | + * @return EE_Registration |
|
169 | + */ |
|
170 | + public function registration() |
|
171 | + { |
|
172 | + return $this->registration; |
|
173 | + } |
|
174 | 174 | } |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | ) { |
80 | 80 | // grab the related ticket object for this line_item |
81 | 81 | $this->ticket = $ticket_line_item->ticket(); |
82 | - if (! $this->ticket instanceof EE_Ticket) { |
|
82 | + if ( ! $this->ticket instanceof EE_Ticket) { |
|
83 | 83 | throw new InvalidEntityException( |
84 | 84 | is_object($this->ticket) ? get_class($this->ticket) : gettype($this->ticket), |
85 | 85 | 'EE_Ticket', |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | */ |
104 | 104 | public function getCapCheck() |
105 | 105 | { |
106 | - if (! $this->cap_check instanceof CapCheckInterface) { |
|
106 | + if ( ! $this->cap_check instanceof CapCheckInterface) { |
|
107 | 107 | return new CapCheck('ee_edit_registrations', 'create_new_registration'); |
108 | 108 | } |
109 | 109 | return $this->cap_check; |
@@ -15,22 +15,22 @@ |
||
15 | 15 | class AddActionHook implements CommandBusMiddlewareInterface |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * @param CommandInterface $command |
|
20 | - * @param Closure $next |
|
21 | - * @return mixed |
|
22 | - */ |
|
23 | - public function handle(CommandInterface $command, Closure $next) |
|
24 | - { |
|
25 | - do_action( |
|
26 | - 'AHEE__EventEspresso_core_services_commands_middleware_AddActionHook__handle__before', |
|
27 | - $command |
|
28 | - ); |
|
29 | - $results = $next($command); |
|
30 | - do_action( |
|
31 | - 'AHEE__EventEspresso_core_services_commands_middleware_AddActionHook__handle__after', |
|
32 | - $command |
|
33 | - ); |
|
34 | - return $results; |
|
35 | - } |
|
18 | + /** |
|
19 | + * @param CommandInterface $command |
|
20 | + * @param Closure $next |
|
21 | + * @return mixed |
|
22 | + */ |
|
23 | + public function handle(CommandInterface $command, Closure $next) |
|
24 | + { |
|
25 | + do_action( |
|
26 | + 'AHEE__EventEspresso_core_services_commands_middleware_AddActionHook__handle__before', |
|
27 | + $command |
|
28 | + ); |
|
29 | + $results = $next($command); |
|
30 | + do_action( |
|
31 | + 'AHEE__EventEspresso_core_services_commands_middleware_AddActionHook__handle__after', |
|
32 | + $command |
|
33 | + ); |
|
34 | + return $results; |
|
35 | + } |
|
36 | 36 | } |
@@ -16,35 +16,35 @@ |
||
16 | 16 | { |
17 | 17 | |
18 | 18 | |
19 | - /** |
|
20 | - * @access public |
|
21 | - * @param mixed $command_bus_middleware_object |
|
22 | - * @param string $message |
|
23 | - * @param int $code |
|
24 | - * @param \Exception $previous |
|
25 | - */ |
|
26 | - public function __construct($command_bus_middleware_object, $message = '', $code = 0, \Exception $previous = null) |
|
27 | - { |
|
28 | - $command_bus_middleware = is_object($command_bus_middleware_object) |
|
29 | - ? get_class($command_bus_middleware_object) |
|
30 | - : gettype($command_bus_middleware_object); |
|
19 | + /** |
|
20 | + * @access public |
|
21 | + * @param mixed $command_bus_middleware_object |
|
22 | + * @param string $message |
|
23 | + * @param int $code |
|
24 | + * @param \Exception $previous |
|
25 | + */ |
|
26 | + public function __construct($command_bus_middleware_object, $message = '', $code = 0, \Exception $previous = null) |
|
27 | + { |
|
28 | + $command_bus_middleware = is_object($command_bus_middleware_object) |
|
29 | + ? get_class($command_bus_middleware_object) |
|
30 | + : gettype($command_bus_middleware_object); |
|
31 | 31 | |
32 | - if (empty($message)) { |
|
33 | - $message = sprintf( |
|
34 | - __( |
|
35 | - 'The supplied Command Bus Middleware "%1$s" does not have a valid name. It should be in the following format: "{CommandName}Handler" ', |
|
36 | - 'event_espresso' |
|
37 | - ), |
|
38 | - $command_bus_middleware |
|
39 | - ); |
|
40 | - } |
|
41 | - parent::__construct( |
|
42 | - '$command_bus_middleware', |
|
43 | - $command_bus_middleware, |
|
44 | - 'CommandBusMiddlewareInterface', |
|
45 | - $message, |
|
46 | - $code, |
|
47 | - $previous |
|
48 | - ); |
|
49 | - } |
|
32 | + if (empty($message)) { |
|
33 | + $message = sprintf( |
|
34 | + __( |
|
35 | + 'The supplied Command Bus Middleware "%1$s" does not have a valid name. It should be in the following format: "{CommandName}Handler" ', |
|
36 | + 'event_espresso' |
|
37 | + ), |
|
38 | + $command_bus_middleware |
|
39 | + ); |
|
40 | + } |
|
41 | + parent::__construct( |
|
42 | + '$command_bus_middleware', |
|
43 | + $command_bus_middleware, |
|
44 | + 'CommandBusMiddlewareInterface', |
|
45 | + $message, |
|
46 | + $code, |
|
47 | + $previous |
|
48 | + ); |
|
49 | + } |
|
50 | 50 | } |
@@ -24,37 +24,37 @@ |
||
24 | 24 | class CapChecker implements CommandBusMiddlewareInterface |
25 | 25 | { |
26 | 26 | |
27 | - /** |
|
28 | - * @type CapabilitiesCheckerInterface $capabilities_checker |
|
29 | - */ |
|
30 | - private $capabilities_checker; |
|
31 | - |
|
32 | - |
|
33 | - /** |
|
34 | - * CapChecker constructor |
|
35 | - * |
|
36 | - * @param CapabilitiesCheckerInterface $capabilities_checker |
|
37 | - */ |
|
38 | - public function __construct(CapabilitiesCheckerInterface $capabilities_checker) |
|
39 | - { |
|
40 | - $this->capabilities_checker = $capabilities_checker; |
|
41 | - } |
|
42 | - |
|
43 | - |
|
44 | - /** |
|
45 | - * @param CommandInterface $command |
|
46 | - * @param Closure $next |
|
47 | - * @return mixed |
|
48 | - * @throws InvalidClassException |
|
49 | - * @throws InsufficientPermissionsException |
|
50 | - */ |
|
51 | - public function handle(CommandInterface $command, Closure $next) |
|
52 | - { |
|
53 | - if ($command instanceof CommandRequiresCapCheckInterface) { |
|
54 | - $this->capabilities_checker->processCapCheck( |
|
55 | - $command->getCapCheck() |
|
56 | - ); |
|
57 | - } |
|
58 | - return $next($command); |
|
59 | - } |
|
27 | + /** |
|
28 | + * @type CapabilitiesCheckerInterface $capabilities_checker |
|
29 | + */ |
|
30 | + private $capabilities_checker; |
|
31 | + |
|
32 | + |
|
33 | + /** |
|
34 | + * CapChecker constructor |
|
35 | + * |
|
36 | + * @param CapabilitiesCheckerInterface $capabilities_checker |
|
37 | + */ |
|
38 | + public function __construct(CapabilitiesCheckerInterface $capabilities_checker) |
|
39 | + { |
|
40 | + $this->capabilities_checker = $capabilities_checker; |
|
41 | + } |
|
42 | + |
|
43 | + |
|
44 | + /** |
|
45 | + * @param CommandInterface $command |
|
46 | + * @param Closure $next |
|
47 | + * @return mixed |
|
48 | + * @throws InvalidClassException |
|
49 | + * @throws InsufficientPermissionsException |
|
50 | + */ |
|
51 | + public function handle(CommandInterface $command, Closure $next) |
|
52 | + { |
|
53 | + if ($command instanceof CommandRequiresCapCheckInterface) { |
|
54 | + $this->capabilities_checker->processCapCheck( |
|
55 | + $command->getCapCheck() |
|
56 | + ); |
|
57 | + } |
|
58 | + return $next($command); |
|
59 | + } |
|
60 | 60 | } |
@@ -16,112 +16,112 @@ |
||
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 | } |
@@ -16,77 +16,77 @@ |
||
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 | } |
@@ -170,7 +170,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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' => ' ', |
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 |
||
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 |
||
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' => ' ', |
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 |
||
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 |
||
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( |
@@ -29,639 +29,639 @@ |
||
29 | 29 | abstract class FormHandler implements FormHandlerInterface |
30 | 30 | { |
31 | 31 | |
32 | - /** |
|
33 | - * will add opening and closing HTML form tags as well as a submit button |
|
34 | - */ |
|
35 | - const ADD_FORM_TAGS_AND_SUBMIT = 'add_form_tags_and_submit'; |
|
36 | - |
|
37 | - /** |
|
38 | - * will add opening and closing HTML form tags but NOT a submit button |
|
39 | - */ |
|
40 | - const ADD_FORM_TAGS_ONLY = 'add_form_tags_only'; |
|
41 | - |
|
42 | - /** |
|
43 | - * will NOT add opening and closing HTML form tags but will add a submit button |
|
44 | - */ |
|
45 | - const ADD_FORM_SUBMIT_ONLY = 'add_form_submit_only'; |
|
46 | - |
|
47 | - /** |
|
48 | - * will NOT add opening and closing HTML form tags NOR a submit button |
|
49 | - */ |
|
50 | - const DO_NOT_SETUP_FORM = 'do_not_setup_form'; |
|
51 | - |
|
52 | - /** |
|
53 | - * if set to false, then this form has no displayable content, |
|
54 | - * and will only be used for processing data sent passed via GET or POST |
|
55 | - * defaults to true ( ie: form has displayable content ) |
|
56 | - * |
|
57 | - * @var boolean $displayable |
|
58 | - */ |
|
59 | - private $displayable = true; |
|
60 | - |
|
61 | - /** |
|
62 | - * @var string $form_name |
|
63 | - */ |
|
64 | - private $form_name; |
|
65 | - |
|
66 | - /** |
|
67 | - * @var string $admin_name |
|
68 | - */ |
|
69 | - private $admin_name; |
|
70 | - |
|
71 | - /** |
|
72 | - * @var string $slug |
|
73 | - */ |
|
74 | - private $slug; |
|
75 | - |
|
76 | - /** |
|
77 | - * @var string $submit_btn_text |
|
78 | - */ |
|
79 | - private $submit_btn_text; |
|
80 | - |
|
81 | - /** |
|
82 | - * @var string $form_action |
|
83 | - */ |
|
84 | - private $form_action; |
|
85 | - |
|
86 | - /** |
|
87 | - * form params in key value pairs |
|
88 | - * can be added to form action URL or as hidden inputs |
|
89 | - * |
|
90 | - * @var array $form_args |
|
91 | - */ |
|
92 | - private $form_args = array(); |
|
93 | - |
|
94 | - /** |
|
95 | - * value of one of the string constant above |
|
96 | - * |
|
97 | - * @var string $form_config |
|
98 | - */ |
|
99 | - private $form_config; |
|
100 | - |
|
101 | - /** |
|
102 | - * whether or not the form was determined to be invalid |
|
103 | - * |
|
104 | - * @var boolean $form_has_errors |
|
105 | - */ |
|
106 | - private $form_has_errors; |
|
107 | - |
|
108 | - /** |
|
109 | - * the absolute top level form section being used on the page |
|
110 | - * |
|
111 | - * @var EE_Form_Section_Proper $form |
|
112 | - */ |
|
113 | - private $form; |
|
114 | - |
|
115 | - /** |
|
116 | - * @var EE_Registry $registry |
|
117 | - */ |
|
118 | - protected $registry; |
|
119 | - |
|
120 | - // phpcs:disable PEAR.Functions.ValidDefaultValue.NotAtEnd |
|
121 | - /** |
|
122 | - * Form constructor. |
|
123 | - * |
|
124 | - * @param string $form_name |
|
125 | - * @param string $admin_name |
|
126 | - * @param string $slug |
|
127 | - * @param string $form_action |
|
128 | - * @param string $form_config |
|
129 | - * @param EE_Registry $registry |
|
130 | - * @throws InvalidDataTypeException |
|
131 | - * @throws DomainException |
|
132 | - * @throws InvalidArgumentException |
|
133 | - */ |
|
134 | - public function __construct( |
|
135 | - $form_name, |
|
136 | - $admin_name, |
|
137 | - $slug, |
|
138 | - $form_action = '', |
|
139 | - $form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
140 | - EE_Registry $registry |
|
141 | - ) { |
|
142 | - $this->setFormName($form_name); |
|
143 | - $this->setAdminName($admin_name); |
|
144 | - $this->setSlug($slug); |
|
145 | - $this->setFormAction($form_action); |
|
146 | - $this->setFormConfig($form_config); |
|
147 | - $this->setSubmitBtnText(esc_html__('Submit', 'event_espresso')); |
|
148 | - $this->registry = $registry; |
|
149 | - } |
|
150 | - |
|
151 | - |
|
152 | - /** |
|
153 | - * @return array |
|
154 | - */ |
|
155 | - public static function getFormConfigConstants() |
|
156 | - { |
|
157 | - return array( |
|
158 | - FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
159 | - FormHandler::ADD_FORM_TAGS_ONLY, |
|
160 | - FormHandler::ADD_FORM_SUBMIT_ONLY, |
|
161 | - FormHandler::DO_NOT_SETUP_FORM, |
|
162 | - ); |
|
163 | - } |
|
164 | - |
|
165 | - |
|
166 | - /** |
|
167 | - * @param bool $for_display |
|
168 | - * @return EE_Form_Section_Proper |
|
169 | - * @throws EE_Error |
|
170 | - * @throws LogicException |
|
171 | - */ |
|
172 | - public function form($for_display = false) |
|
173 | - { |
|
174 | - if (! $this->formIsValid()) { |
|
175 | - return null; |
|
176 | - } |
|
177 | - if ($for_display) { |
|
178 | - $form_config = $this->formConfig(); |
|
179 | - if ($form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
180 | - || $form_config === FormHandler::ADD_FORM_SUBMIT_ONLY |
|
181 | - ) { |
|
182 | - $this->appendSubmitButton(); |
|
183 | - $this->clearFormButtonFloats(); |
|
184 | - } |
|
185 | - } |
|
186 | - return $this->form; |
|
187 | - } |
|
188 | - |
|
189 | - |
|
190 | - /** |
|
191 | - * @return boolean |
|
192 | - * @throws LogicException |
|
193 | - */ |
|
194 | - public function formIsValid() |
|
195 | - { |
|
196 | - if ($this->form instanceof EE_Form_Section_Proper) { |
|
197 | - return true; |
|
198 | - } |
|
199 | - $form = apply_filters( |
|
200 | - 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__formIsValid__generated_form_object', |
|
201 | - $this->generate(), |
|
202 | - $this |
|
203 | - ); |
|
204 | - if ($this->verifyForm($form)) { |
|
205 | - $this->setForm($form); |
|
206 | - } |
|
207 | - return true; |
|
208 | - } |
|
209 | - |
|
210 | - |
|
211 | - /** |
|
212 | - * @param EE_Form_Section_Proper|null $form |
|
213 | - * @return bool |
|
214 | - * @throws LogicException |
|
215 | - */ |
|
216 | - public function verifyForm(EE_Form_Section_Proper $form = null) |
|
217 | - { |
|
218 | - $form = $form !== null ? $form : $this->form; |
|
219 | - if ($form instanceof EE_Form_Section_Proper) { |
|
220 | - return true; |
|
221 | - } |
|
222 | - throw new LogicException( |
|
223 | - sprintf( |
|
224 | - esc_html__('The "%1$s" form is invalid or missing. %2$s', 'event_espresso'), |
|
225 | - $this->form_name, |
|
226 | - var_export($form, true) |
|
227 | - ) |
|
228 | - ); |
|
229 | - } |
|
230 | - |
|
231 | - |
|
232 | - /** |
|
233 | - * @param EE_Form_Section_Proper $form |
|
234 | - */ |
|
235 | - public function setForm(EE_Form_Section_Proper $form) |
|
236 | - { |
|
237 | - $this->form = $form; |
|
238 | - } |
|
239 | - |
|
240 | - |
|
241 | - /** |
|
242 | - * @return boolean |
|
243 | - */ |
|
244 | - public function displayable() |
|
245 | - { |
|
246 | - return $this->displayable; |
|
247 | - } |
|
248 | - |
|
249 | - |
|
250 | - /** |
|
251 | - * @param boolean $displayable |
|
252 | - */ |
|
253 | - public function setDisplayable($displayable = false) |
|
254 | - { |
|
255 | - $this->displayable = filter_var($displayable, FILTER_VALIDATE_BOOLEAN); |
|
256 | - } |
|
257 | - |
|
258 | - |
|
259 | - /** |
|
260 | - * a public name for the form that can be displayed on the frontend of a site |
|
261 | - * |
|
262 | - * @return string |
|
263 | - */ |
|
264 | - public function formName() |
|
265 | - { |
|
266 | - return $this->form_name; |
|
267 | - } |
|
268 | - |
|
269 | - |
|
270 | - /** |
|
271 | - * @param string $form_name |
|
272 | - * @throws InvalidDataTypeException |
|
273 | - */ |
|
274 | - public function setFormName($form_name) |
|
275 | - { |
|
276 | - if (! is_string($form_name)) { |
|
277 | - throw new InvalidDataTypeException('$form_name', $form_name, 'string'); |
|
278 | - } |
|
279 | - $this->form_name = $form_name; |
|
280 | - } |
|
281 | - |
|
282 | - |
|
283 | - /** |
|
284 | - * a public name for the form that can be displayed, but only in the admin |
|
285 | - * |
|
286 | - * @return string |
|
287 | - */ |
|
288 | - public function adminName() |
|
289 | - { |
|
290 | - return $this->admin_name; |
|
291 | - } |
|
292 | - |
|
293 | - |
|
294 | - /** |
|
295 | - * @param string $admin_name |
|
296 | - * @throws InvalidDataTypeException |
|
297 | - */ |
|
298 | - public function setAdminName($admin_name) |
|
299 | - { |
|
300 | - if (! is_string($admin_name)) { |
|
301 | - throw new InvalidDataTypeException('$admin_name', $admin_name, 'string'); |
|
302 | - } |
|
303 | - $this->admin_name = $admin_name; |
|
304 | - } |
|
305 | - |
|
306 | - |
|
307 | - /** |
|
308 | - * a URL friendly string that can be used for identifying the form |
|
309 | - * |
|
310 | - * @return string |
|
311 | - */ |
|
312 | - public function slug() |
|
313 | - { |
|
314 | - return $this->slug; |
|
315 | - } |
|
316 | - |
|
317 | - |
|
318 | - /** |
|
319 | - * @param string $slug |
|
320 | - * @throws InvalidDataTypeException |
|
321 | - */ |
|
322 | - public function setSlug($slug) |
|
323 | - { |
|
324 | - if (! is_string($slug)) { |
|
325 | - throw new InvalidDataTypeException('$slug', $slug, 'string'); |
|
326 | - } |
|
327 | - $this->slug = $slug; |
|
328 | - } |
|
329 | - |
|
330 | - |
|
331 | - /** |
|
332 | - * @return string |
|
333 | - */ |
|
334 | - public function submitBtnText() |
|
335 | - { |
|
336 | - return $this->submit_btn_text; |
|
337 | - } |
|
338 | - |
|
339 | - |
|
340 | - /** |
|
341 | - * @param string $submit_btn_text |
|
342 | - * @throws InvalidDataTypeException |
|
343 | - * @throws InvalidArgumentException |
|
344 | - */ |
|
345 | - public function setSubmitBtnText($submit_btn_text) |
|
346 | - { |
|
347 | - if (! is_string($submit_btn_text)) { |
|
348 | - throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string'); |
|
349 | - } |
|
350 | - if (empty($submit_btn_text)) { |
|
351 | - throw new InvalidArgumentException( |
|
352 | - esc_html__('Can not set Submit button text because an empty string was provided.', 'event_espresso') |
|
353 | - ); |
|
354 | - } |
|
355 | - $this->submit_btn_text = $submit_btn_text; |
|
356 | - } |
|
357 | - |
|
358 | - |
|
359 | - /** |
|
360 | - * @return string |
|
361 | - */ |
|
362 | - public function formAction() |
|
363 | - { |
|
364 | - return ! empty($this->form_args) |
|
365 | - ? add_query_arg($this->form_args, $this->form_action) |
|
366 | - : $this->form_action; |
|
367 | - } |
|
368 | - |
|
369 | - |
|
370 | - /** |
|
371 | - * @param string $form_action |
|
372 | - * @throws InvalidDataTypeException |
|
373 | - */ |
|
374 | - public function setFormAction($form_action) |
|
375 | - { |
|
376 | - if (! is_string($form_action)) { |
|
377 | - throw new InvalidDataTypeException('$form_action', $form_action, 'string'); |
|
378 | - } |
|
379 | - $this->form_action = $form_action; |
|
380 | - } |
|
381 | - |
|
382 | - |
|
383 | - /** |
|
384 | - * @param array $form_args |
|
385 | - * @throws InvalidDataTypeException |
|
386 | - * @throws InvalidArgumentException |
|
387 | - */ |
|
388 | - public function addFormActionArgs($form_args = array()) |
|
389 | - { |
|
390 | - if (is_object($form_args)) { |
|
391 | - throw new InvalidDataTypeException( |
|
392 | - '$form_args', |
|
393 | - $form_args, |
|
394 | - 'anything other than an object was expected.' |
|
395 | - ); |
|
396 | - } |
|
397 | - if (empty($form_args)) { |
|
398 | - throw new InvalidArgumentException( |
|
399 | - esc_html__('The redirect arguments can not be an empty array.', 'event_espresso') |
|
400 | - ); |
|
401 | - } |
|
402 | - $this->form_args = array_merge($this->form_args, $form_args); |
|
403 | - } |
|
404 | - |
|
405 | - |
|
406 | - /** |
|
407 | - * @return string |
|
408 | - */ |
|
409 | - public function formConfig() |
|
410 | - { |
|
411 | - return $this->form_config; |
|
412 | - } |
|
413 | - |
|
414 | - |
|
415 | - /** |
|
416 | - * @param string $form_config |
|
417 | - * @throws DomainException |
|
418 | - */ |
|
419 | - public function setFormConfig($form_config) |
|
420 | - { |
|
421 | - if (! in_array( |
|
422 | - $form_config, |
|
423 | - array( |
|
424 | - FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
425 | - FormHandler::ADD_FORM_TAGS_ONLY, |
|
426 | - FormHandler::ADD_FORM_SUBMIT_ONLY, |
|
427 | - FormHandler::DO_NOT_SETUP_FORM, |
|
428 | - ), |
|
429 | - true |
|
430 | - ) |
|
431 | - ) { |
|
432 | - throw new DomainException( |
|
433 | - sprintf( |
|
434 | - esc_html__( |
|
435 | - '"%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', |
|
436 | - 'event_espresso' |
|
437 | - ), |
|
438 | - $form_config |
|
439 | - ) |
|
440 | - ); |
|
441 | - } |
|
442 | - $this->form_config = $form_config; |
|
443 | - } |
|
444 | - |
|
445 | - |
|
446 | - /** |
|
447 | - * called after the form is instantiated |
|
448 | - * and used for performing any logic that needs to occur early |
|
449 | - * before any of the other methods are called. |
|
450 | - * returns true if everything is ok to proceed, |
|
451 | - * and false if no further form logic should be implemented |
|
452 | - * |
|
453 | - * @return boolean |
|
454 | - */ |
|
455 | - public function initialize() |
|
456 | - { |
|
457 | - $this->form_has_errors = EE_Error::has_error(true); |
|
458 | - return true; |
|
459 | - } |
|
460 | - |
|
461 | - |
|
462 | - /** |
|
463 | - * used for setting up css and js |
|
464 | - * |
|
465 | - * @return void |
|
466 | - * @throws LogicException |
|
467 | - * @throws EE_Error |
|
468 | - */ |
|
469 | - public function enqueueStylesAndScripts() |
|
470 | - { |
|
471 | - $this->form()->enqueue_js(); |
|
472 | - } |
|
473 | - |
|
474 | - |
|
475 | - /** |
|
476 | - * creates and returns the actual form |
|
477 | - * |
|
478 | - * @return EE_Form_Section_Proper |
|
479 | - */ |
|
480 | - abstract public function generate(); |
|
481 | - |
|
482 | - |
|
483 | - /** |
|
484 | - * creates and returns an EE_Submit_Input labeled "Submit" |
|
485 | - * |
|
486 | - * @param string $text |
|
487 | - * @return EE_Submit_Input |
|
488 | - */ |
|
489 | - public function generateSubmitButton($text = '') |
|
490 | - { |
|
491 | - $text = ! empty($text) ? $text : $this->submitBtnText(); |
|
492 | - return new EE_Submit_Input( |
|
493 | - array( |
|
494 | - 'html_name' => 'ee-form-submit-' . $this->slug(), |
|
495 | - 'html_id' => 'ee-form-submit-' . $this->slug(), |
|
496 | - 'html_class' => 'ee-form-submit', |
|
497 | - 'html_label' => ' ', |
|
498 | - 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
499 | - 'default' => $text, |
|
500 | - ) |
|
501 | - ); |
|
502 | - } |
|
503 | - |
|
504 | - |
|
505 | - /** |
|
506 | - * calls generateSubmitButton() and appends it onto the form along with a float clearing div |
|
507 | - * |
|
508 | - * @param string $text |
|
509 | - * @return void |
|
510 | - * @throws EE_Error |
|
511 | - */ |
|
512 | - public function appendSubmitButton($text = '') |
|
513 | - { |
|
514 | - if ($this->form->subsection_exists($this->slug() . '-submit-btn')) { |
|
515 | - return; |
|
516 | - } |
|
517 | - $this->form->add_subsections( |
|
518 | - array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)), |
|
519 | - null, |
|
520 | - false |
|
521 | - ); |
|
522 | - } |
|
523 | - |
|
524 | - |
|
525 | - /** |
|
526 | - * creates and returns an EE_Submit_Input labeled "Cancel" |
|
527 | - * |
|
528 | - * @param string $text |
|
529 | - * @return EE_Submit_Input |
|
530 | - */ |
|
531 | - public function generateCancelButton($text = '') |
|
532 | - { |
|
533 | - $cancel_button = new EE_Submit_Input( |
|
534 | - array( |
|
535 | - 'html_name' => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!! |
|
536 | - 'html_id' => 'ee-cancel-form-' . $this->slug(), |
|
537 | - 'html_class' => 'ee-cancel-form', |
|
538 | - 'html_label' => ' ', |
|
539 | - 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
540 | - 'default' => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'), |
|
541 | - ) |
|
542 | - ); |
|
543 | - $cancel_button->set_button_css_attributes(false); |
|
544 | - return $cancel_button; |
|
545 | - } |
|
546 | - |
|
547 | - |
|
548 | - /** |
|
549 | - * appends a float clearing div onto end of form |
|
550 | - * |
|
551 | - * @return void |
|
552 | - * @throws EE_Error |
|
553 | - */ |
|
554 | - public function clearFormButtonFloats() |
|
555 | - { |
|
556 | - $this->form->add_subsections( |
|
557 | - array( |
|
558 | - 'clear-submit-btn-float' => new EE_Form_Section_HTML( |
|
559 | - EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx() |
|
560 | - ), |
|
561 | - ), |
|
562 | - null, |
|
563 | - false |
|
564 | - ); |
|
565 | - } |
|
566 | - |
|
567 | - |
|
568 | - /** |
|
569 | - * takes the generated form and displays it along with ony other non-form HTML that may be required |
|
570 | - * returns a string of HTML that can be directly echoed in a template |
|
571 | - * |
|
572 | - * @return string |
|
573 | - * @throws \InvalidArgumentException |
|
574 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
575 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
576 | - * @throws LogicException |
|
577 | - * @throws EE_Error |
|
578 | - */ |
|
579 | - public function display() |
|
580 | - { |
|
581 | - $form_html = apply_filters( |
|
582 | - 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__before_form', |
|
583 | - '' |
|
584 | - ); |
|
585 | - $form_config = $this->formConfig(); |
|
586 | - if ($form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
587 | - || $form_config === FormHandler::ADD_FORM_TAGS_ONLY |
|
588 | - ) { |
|
589 | - $additional_props = $this->requiresMultipartEnctype() |
|
590 | - ? 'enctype="multipart/form-data"' |
|
591 | - : ''; |
|
592 | - $form_html .= $this->form()->form_open( |
|
593 | - $this->formAction(), |
|
594 | - 'POST', |
|
595 | - $additional_props |
|
596 | - ); |
|
597 | - } |
|
598 | - $form_html .= $this->form(true)->get_html(); |
|
599 | - if ($form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
600 | - || $form_config === FormHandler::ADD_FORM_TAGS_ONLY |
|
601 | - ) { |
|
602 | - $form_html .= $this->form()->form_close(); |
|
603 | - } |
|
604 | - $form_html .= apply_filters( |
|
605 | - 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__after_form', |
|
606 | - '' |
|
607 | - ); |
|
608 | - return $form_html; |
|
609 | - } |
|
610 | - |
|
611 | - /** |
|
612 | - * Determines if this form needs "enctype='multipart/form-data'" or not. |
|
613 | - * @since 4.9.80.p |
|
614 | - * @return bool |
|
615 | - * @throws EE_Error |
|
616 | - */ |
|
617 | - public function requiresMultipartEnctype() |
|
618 | - { |
|
619 | - foreach ($this->form()->inputs_in_subsections() as $input) { |
|
620 | - if ($input instanceof EE_File_Input) { |
|
621 | - return true; |
|
622 | - } |
|
623 | - } |
|
624 | - return false; |
|
625 | - } |
|
626 | - |
|
627 | - |
|
628 | - /** |
|
629 | - * handles processing the form submission |
|
630 | - * returns true or false depending on whether the form was processed successfully or not |
|
631 | - * |
|
632 | - * @param array $submitted_form_data |
|
633 | - * @return array |
|
634 | - * @throws \InvalidArgumentException |
|
635 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
636 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
637 | - * @throws EE_Error |
|
638 | - * @throws LogicException |
|
639 | - * @throws InvalidFormSubmissionException |
|
640 | - */ |
|
641 | - public function process($submitted_form_data = array()) |
|
642 | - { |
|
643 | - if (! $this->form()->was_submitted($submitted_form_data)) { |
|
644 | - throw new InvalidFormSubmissionException($this->form_name); |
|
645 | - } |
|
646 | - $this->form(true)->receive_form_submission($submitted_form_data); |
|
647 | - if (! $this->form()->is_valid()) { |
|
648 | - throw new InvalidFormSubmissionException( |
|
649 | - $this->form_name, |
|
650 | - sprintf( |
|
651 | - esc_html__( |
|
652 | - 'The "%1$s" form is invalid. Please correct the following errors and resubmit: %2$s %3$s', |
|
653 | - 'event_espresso' |
|
654 | - ), |
|
655 | - $this->form_name, |
|
656 | - '<br />', |
|
657 | - implode('<br />', $this->form()->get_validation_errors_accumulated()) |
|
658 | - ) |
|
659 | - ); |
|
660 | - } |
|
661 | - return apply_filters( |
|
662 | - 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__process__valid_data', |
|
663 | - $this->form()->valid_data(), |
|
664 | - $this |
|
665 | - ); |
|
666 | - } |
|
32 | + /** |
|
33 | + * will add opening and closing HTML form tags as well as a submit button |
|
34 | + */ |
|
35 | + const ADD_FORM_TAGS_AND_SUBMIT = 'add_form_tags_and_submit'; |
|
36 | + |
|
37 | + /** |
|
38 | + * will add opening and closing HTML form tags but NOT a submit button |
|
39 | + */ |
|
40 | + const ADD_FORM_TAGS_ONLY = 'add_form_tags_only'; |
|
41 | + |
|
42 | + /** |
|
43 | + * will NOT add opening and closing HTML form tags but will add a submit button |
|
44 | + */ |
|
45 | + const ADD_FORM_SUBMIT_ONLY = 'add_form_submit_only'; |
|
46 | + |
|
47 | + /** |
|
48 | + * will NOT add opening and closing HTML form tags NOR a submit button |
|
49 | + */ |
|
50 | + const DO_NOT_SETUP_FORM = 'do_not_setup_form'; |
|
51 | + |
|
52 | + /** |
|
53 | + * if set to false, then this form has no displayable content, |
|
54 | + * and will only be used for processing data sent passed via GET or POST |
|
55 | + * defaults to true ( ie: form has displayable content ) |
|
56 | + * |
|
57 | + * @var boolean $displayable |
|
58 | + */ |
|
59 | + private $displayable = true; |
|
60 | + |
|
61 | + /** |
|
62 | + * @var string $form_name |
|
63 | + */ |
|
64 | + private $form_name; |
|
65 | + |
|
66 | + /** |
|
67 | + * @var string $admin_name |
|
68 | + */ |
|
69 | + private $admin_name; |
|
70 | + |
|
71 | + /** |
|
72 | + * @var string $slug |
|
73 | + */ |
|
74 | + private $slug; |
|
75 | + |
|
76 | + /** |
|
77 | + * @var string $submit_btn_text |
|
78 | + */ |
|
79 | + private $submit_btn_text; |
|
80 | + |
|
81 | + /** |
|
82 | + * @var string $form_action |
|
83 | + */ |
|
84 | + private $form_action; |
|
85 | + |
|
86 | + /** |
|
87 | + * form params in key value pairs |
|
88 | + * can be added to form action URL or as hidden inputs |
|
89 | + * |
|
90 | + * @var array $form_args |
|
91 | + */ |
|
92 | + private $form_args = array(); |
|
93 | + |
|
94 | + /** |
|
95 | + * value of one of the string constant above |
|
96 | + * |
|
97 | + * @var string $form_config |
|
98 | + */ |
|
99 | + private $form_config; |
|
100 | + |
|
101 | + /** |
|
102 | + * whether or not the form was determined to be invalid |
|
103 | + * |
|
104 | + * @var boolean $form_has_errors |
|
105 | + */ |
|
106 | + private $form_has_errors; |
|
107 | + |
|
108 | + /** |
|
109 | + * the absolute top level form section being used on the page |
|
110 | + * |
|
111 | + * @var EE_Form_Section_Proper $form |
|
112 | + */ |
|
113 | + private $form; |
|
114 | + |
|
115 | + /** |
|
116 | + * @var EE_Registry $registry |
|
117 | + */ |
|
118 | + protected $registry; |
|
119 | + |
|
120 | + // phpcs:disable PEAR.Functions.ValidDefaultValue.NotAtEnd |
|
121 | + /** |
|
122 | + * Form constructor. |
|
123 | + * |
|
124 | + * @param string $form_name |
|
125 | + * @param string $admin_name |
|
126 | + * @param string $slug |
|
127 | + * @param string $form_action |
|
128 | + * @param string $form_config |
|
129 | + * @param EE_Registry $registry |
|
130 | + * @throws InvalidDataTypeException |
|
131 | + * @throws DomainException |
|
132 | + * @throws InvalidArgumentException |
|
133 | + */ |
|
134 | + public function __construct( |
|
135 | + $form_name, |
|
136 | + $admin_name, |
|
137 | + $slug, |
|
138 | + $form_action = '', |
|
139 | + $form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
140 | + EE_Registry $registry |
|
141 | + ) { |
|
142 | + $this->setFormName($form_name); |
|
143 | + $this->setAdminName($admin_name); |
|
144 | + $this->setSlug($slug); |
|
145 | + $this->setFormAction($form_action); |
|
146 | + $this->setFormConfig($form_config); |
|
147 | + $this->setSubmitBtnText(esc_html__('Submit', 'event_espresso')); |
|
148 | + $this->registry = $registry; |
|
149 | + } |
|
150 | + |
|
151 | + |
|
152 | + /** |
|
153 | + * @return array |
|
154 | + */ |
|
155 | + public static function getFormConfigConstants() |
|
156 | + { |
|
157 | + return array( |
|
158 | + FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
159 | + FormHandler::ADD_FORM_TAGS_ONLY, |
|
160 | + FormHandler::ADD_FORM_SUBMIT_ONLY, |
|
161 | + FormHandler::DO_NOT_SETUP_FORM, |
|
162 | + ); |
|
163 | + } |
|
164 | + |
|
165 | + |
|
166 | + /** |
|
167 | + * @param bool $for_display |
|
168 | + * @return EE_Form_Section_Proper |
|
169 | + * @throws EE_Error |
|
170 | + * @throws LogicException |
|
171 | + */ |
|
172 | + public function form($for_display = false) |
|
173 | + { |
|
174 | + if (! $this->formIsValid()) { |
|
175 | + return null; |
|
176 | + } |
|
177 | + if ($for_display) { |
|
178 | + $form_config = $this->formConfig(); |
|
179 | + if ($form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
180 | + || $form_config === FormHandler::ADD_FORM_SUBMIT_ONLY |
|
181 | + ) { |
|
182 | + $this->appendSubmitButton(); |
|
183 | + $this->clearFormButtonFloats(); |
|
184 | + } |
|
185 | + } |
|
186 | + return $this->form; |
|
187 | + } |
|
188 | + |
|
189 | + |
|
190 | + /** |
|
191 | + * @return boolean |
|
192 | + * @throws LogicException |
|
193 | + */ |
|
194 | + public function formIsValid() |
|
195 | + { |
|
196 | + if ($this->form instanceof EE_Form_Section_Proper) { |
|
197 | + return true; |
|
198 | + } |
|
199 | + $form = apply_filters( |
|
200 | + 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__formIsValid__generated_form_object', |
|
201 | + $this->generate(), |
|
202 | + $this |
|
203 | + ); |
|
204 | + if ($this->verifyForm($form)) { |
|
205 | + $this->setForm($form); |
|
206 | + } |
|
207 | + return true; |
|
208 | + } |
|
209 | + |
|
210 | + |
|
211 | + /** |
|
212 | + * @param EE_Form_Section_Proper|null $form |
|
213 | + * @return bool |
|
214 | + * @throws LogicException |
|
215 | + */ |
|
216 | + public function verifyForm(EE_Form_Section_Proper $form = null) |
|
217 | + { |
|
218 | + $form = $form !== null ? $form : $this->form; |
|
219 | + if ($form instanceof EE_Form_Section_Proper) { |
|
220 | + return true; |
|
221 | + } |
|
222 | + throw new LogicException( |
|
223 | + sprintf( |
|
224 | + esc_html__('The "%1$s" form is invalid or missing. %2$s', 'event_espresso'), |
|
225 | + $this->form_name, |
|
226 | + var_export($form, true) |
|
227 | + ) |
|
228 | + ); |
|
229 | + } |
|
230 | + |
|
231 | + |
|
232 | + /** |
|
233 | + * @param EE_Form_Section_Proper $form |
|
234 | + */ |
|
235 | + public function setForm(EE_Form_Section_Proper $form) |
|
236 | + { |
|
237 | + $this->form = $form; |
|
238 | + } |
|
239 | + |
|
240 | + |
|
241 | + /** |
|
242 | + * @return boolean |
|
243 | + */ |
|
244 | + public function displayable() |
|
245 | + { |
|
246 | + return $this->displayable; |
|
247 | + } |
|
248 | + |
|
249 | + |
|
250 | + /** |
|
251 | + * @param boolean $displayable |
|
252 | + */ |
|
253 | + public function setDisplayable($displayable = false) |
|
254 | + { |
|
255 | + $this->displayable = filter_var($displayable, FILTER_VALIDATE_BOOLEAN); |
|
256 | + } |
|
257 | + |
|
258 | + |
|
259 | + /** |
|
260 | + * a public name for the form that can be displayed on the frontend of a site |
|
261 | + * |
|
262 | + * @return string |
|
263 | + */ |
|
264 | + public function formName() |
|
265 | + { |
|
266 | + return $this->form_name; |
|
267 | + } |
|
268 | + |
|
269 | + |
|
270 | + /** |
|
271 | + * @param string $form_name |
|
272 | + * @throws InvalidDataTypeException |
|
273 | + */ |
|
274 | + public function setFormName($form_name) |
|
275 | + { |
|
276 | + if (! is_string($form_name)) { |
|
277 | + throw new InvalidDataTypeException('$form_name', $form_name, 'string'); |
|
278 | + } |
|
279 | + $this->form_name = $form_name; |
|
280 | + } |
|
281 | + |
|
282 | + |
|
283 | + /** |
|
284 | + * a public name for the form that can be displayed, but only in the admin |
|
285 | + * |
|
286 | + * @return string |
|
287 | + */ |
|
288 | + public function adminName() |
|
289 | + { |
|
290 | + return $this->admin_name; |
|
291 | + } |
|
292 | + |
|
293 | + |
|
294 | + /** |
|
295 | + * @param string $admin_name |
|
296 | + * @throws InvalidDataTypeException |
|
297 | + */ |
|
298 | + public function setAdminName($admin_name) |
|
299 | + { |
|
300 | + if (! is_string($admin_name)) { |
|
301 | + throw new InvalidDataTypeException('$admin_name', $admin_name, 'string'); |
|
302 | + } |
|
303 | + $this->admin_name = $admin_name; |
|
304 | + } |
|
305 | + |
|
306 | + |
|
307 | + /** |
|
308 | + * a URL friendly string that can be used for identifying the form |
|
309 | + * |
|
310 | + * @return string |
|
311 | + */ |
|
312 | + public function slug() |
|
313 | + { |
|
314 | + return $this->slug; |
|
315 | + } |
|
316 | + |
|
317 | + |
|
318 | + /** |
|
319 | + * @param string $slug |
|
320 | + * @throws InvalidDataTypeException |
|
321 | + */ |
|
322 | + public function setSlug($slug) |
|
323 | + { |
|
324 | + if (! is_string($slug)) { |
|
325 | + throw new InvalidDataTypeException('$slug', $slug, 'string'); |
|
326 | + } |
|
327 | + $this->slug = $slug; |
|
328 | + } |
|
329 | + |
|
330 | + |
|
331 | + /** |
|
332 | + * @return string |
|
333 | + */ |
|
334 | + public function submitBtnText() |
|
335 | + { |
|
336 | + return $this->submit_btn_text; |
|
337 | + } |
|
338 | + |
|
339 | + |
|
340 | + /** |
|
341 | + * @param string $submit_btn_text |
|
342 | + * @throws InvalidDataTypeException |
|
343 | + * @throws InvalidArgumentException |
|
344 | + */ |
|
345 | + public function setSubmitBtnText($submit_btn_text) |
|
346 | + { |
|
347 | + if (! is_string($submit_btn_text)) { |
|
348 | + throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string'); |
|
349 | + } |
|
350 | + if (empty($submit_btn_text)) { |
|
351 | + throw new InvalidArgumentException( |
|
352 | + esc_html__('Can not set Submit button text because an empty string was provided.', 'event_espresso') |
|
353 | + ); |
|
354 | + } |
|
355 | + $this->submit_btn_text = $submit_btn_text; |
|
356 | + } |
|
357 | + |
|
358 | + |
|
359 | + /** |
|
360 | + * @return string |
|
361 | + */ |
|
362 | + public function formAction() |
|
363 | + { |
|
364 | + return ! empty($this->form_args) |
|
365 | + ? add_query_arg($this->form_args, $this->form_action) |
|
366 | + : $this->form_action; |
|
367 | + } |
|
368 | + |
|
369 | + |
|
370 | + /** |
|
371 | + * @param string $form_action |
|
372 | + * @throws InvalidDataTypeException |
|
373 | + */ |
|
374 | + public function setFormAction($form_action) |
|
375 | + { |
|
376 | + if (! is_string($form_action)) { |
|
377 | + throw new InvalidDataTypeException('$form_action', $form_action, 'string'); |
|
378 | + } |
|
379 | + $this->form_action = $form_action; |
|
380 | + } |
|
381 | + |
|
382 | + |
|
383 | + /** |
|
384 | + * @param array $form_args |
|
385 | + * @throws InvalidDataTypeException |
|
386 | + * @throws InvalidArgumentException |
|
387 | + */ |
|
388 | + public function addFormActionArgs($form_args = array()) |
|
389 | + { |
|
390 | + if (is_object($form_args)) { |
|
391 | + throw new InvalidDataTypeException( |
|
392 | + '$form_args', |
|
393 | + $form_args, |
|
394 | + 'anything other than an object was expected.' |
|
395 | + ); |
|
396 | + } |
|
397 | + if (empty($form_args)) { |
|
398 | + throw new InvalidArgumentException( |
|
399 | + esc_html__('The redirect arguments can not be an empty array.', 'event_espresso') |
|
400 | + ); |
|
401 | + } |
|
402 | + $this->form_args = array_merge($this->form_args, $form_args); |
|
403 | + } |
|
404 | + |
|
405 | + |
|
406 | + /** |
|
407 | + * @return string |
|
408 | + */ |
|
409 | + public function formConfig() |
|
410 | + { |
|
411 | + return $this->form_config; |
|
412 | + } |
|
413 | + |
|
414 | + |
|
415 | + /** |
|
416 | + * @param string $form_config |
|
417 | + * @throws DomainException |
|
418 | + */ |
|
419 | + public function setFormConfig($form_config) |
|
420 | + { |
|
421 | + if (! in_array( |
|
422 | + $form_config, |
|
423 | + array( |
|
424 | + FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
425 | + FormHandler::ADD_FORM_TAGS_ONLY, |
|
426 | + FormHandler::ADD_FORM_SUBMIT_ONLY, |
|
427 | + FormHandler::DO_NOT_SETUP_FORM, |
|
428 | + ), |
|
429 | + true |
|
430 | + ) |
|
431 | + ) { |
|
432 | + throw new DomainException( |
|
433 | + sprintf( |
|
434 | + esc_html__( |
|
435 | + '"%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', |
|
436 | + 'event_espresso' |
|
437 | + ), |
|
438 | + $form_config |
|
439 | + ) |
|
440 | + ); |
|
441 | + } |
|
442 | + $this->form_config = $form_config; |
|
443 | + } |
|
444 | + |
|
445 | + |
|
446 | + /** |
|
447 | + * called after the form is instantiated |
|
448 | + * and used for performing any logic that needs to occur early |
|
449 | + * before any of the other methods are called. |
|
450 | + * returns true if everything is ok to proceed, |
|
451 | + * and false if no further form logic should be implemented |
|
452 | + * |
|
453 | + * @return boolean |
|
454 | + */ |
|
455 | + public function initialize() |
|
456 | + { |
|
457 | + $this->form_has_errors = EE_Error::has_error(true); |
|
458 | + return true; |
|
459 | + } |
|
460 | + |
|
461 | + |
|
462 | + /** |
|
463 | + * used for setting up css and js |
|
464 | + * |
|
465 | + * @return void |
|
466 | + * @throws LogicException |
|
467 | + * @throws EE_Error |
|
468 | + */ |
|
469 | + public function enqueueStylesAndScripts() |
|
470 | + { |
|
471 | + $this->form()->enqueue_js(); |
|
472 | + } |
|
473 | + |
|
474 | + |
|
475 | + /** |
|
476 | + * creates and returns the actual form |
|
477 | + * |
|
478 | + * @return EE_Form_Section_Proper |
|
479 | + */ |
|
480 | + abstract public function generate(); |
|
481 | + |
|
482 | + |
|
483 | + /** |
|
484 | + * creates and returns an EE_Submit_Input labeled "Submit" |
|
485 | + * |
|
486 | + * @param string $text |
|
487 | + * @return EE_Submit_Input |
|
488 | + */ |
|
489 | + public function generateSubmitButton($text = '') |
|
490 | + { |
|
491 | + $text = ! empty($text) ? $text : $this->submitBtnText(); |
|
492 | + return new EE_Submit_Input( |
|
493 | + array( |
|
494 | + 'html_name' => 'ee-form-submit-' . $this->slug(), |
|
495 | + 'html_id' => 'ee-form-submit-' . $this->slug(), |
|
496 | + 'html_class' => 'ee-form-submit', |
|
497 | + 'html_label' => ' ', |
|
498 | + 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
499 | + 'default' => $text, |
|
500 | + ) |
|
501 | + ); |
|
502 | + } |
|
503 | + |
|
504 | + |
|
505 | + /** |
|
506 | + * calls generateSubmitButton() and appends it onto the form along with a float clearing div |
|
507 | + * |
|
508 | + * @param string $text |
|
509 | + * @return void |
|
510 | + * @throws EE_Error |
|
511 | + */ |
|
512 | + public function appendSubmitButton($text = '') |
|
513 | + { |
|
514 | + if ($this->form->subsection_exists($this->slug() . '-submit-btn')) { |
|
515 | + return; |
|
516 | + } |
|
517 | + $this->form->add_subsections( |
|
518 | + array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)), |
|
519 | + null, |
|
520 | + false |
|
521 | + ); |
|
522 | + } |
|
523 | + |
|
524 | + |
|
525 | + /** |
|
526 | + * creates and returns an EE_Submit_Input labeled "Cancel" |
|
527 | + * |
|
528 | + * @param string $text |
|
529 | + * @return EE_Submit_Input |
|
530 | + */ |
|
531 | + public function generateCancelButton($text = '') |
|
532 | + { |
|
533 | + $cancel_button = new EE_Submit_Input( |
|
534 | + array( |
|
535 | + 'html_name' => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!! |
|
536 | + 'html_id' => 'ee-cancel-form-' . $this->slug(), |
|
537 | + 'html_class' => 'ee-cancel-form', |
|
538 | + 'html_label' => ' ', |
|
539 | + 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
540 | + 'default' => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'), |
|
541 | + ) |
|
542 | + ); |
|
543 | + $cancel_button->set_button_css_attributes(false); |
|
544 | + return $cancel_button; |
|
545 | + } |
|
546 | + |
|
547 | + |
|
548 | + /** |
|
549 | + * appends a float clearing div onto end of form |
|
550 | + * |
|
551 | + * @return void |
|
552 | + * @throws EE_Error |
|
553 | + */ |
|
554 | + public function clearFormButtonFloats() |
|
555 | + { |
|
556 | + $this->form->add_subsections( |
|
557 | + array( |
|
558 | + 'clear-submit-btn-float' => new EE_Form_Section_HTML( |
|
559 | + EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx() |
|
560 | + ), |
|
561 | + ), |
|
562 | + null, |
|
563 | + false |
|
564 | + ); |
|
565 | + } |
|
566 | + |
|
567 | + |
|
568 | + /** |
|
569 | + * takes the generated form and displays it along with ony other non-form HTML that may be required |
|
570 | + * returns a string of HTML that can be directly echoed in a template |
|
571 | + * |
|
572 | + * @return string |
|
573 | + * @throws \InvalidArgumentException |
|
574 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
575 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
576 | + * @throws LogicException |
|
577 | + * @throws EE_Error |
|
578 | + */ |
|
579 | + public function display() |
|
580 | + { |
|
581 | + $form_html = apply_filters( |
|
582 | + 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__before_form', |
|
583 | + '' |
|
584 | + ); |
|
585 | + $form_config = $this->formConfig(); |
|
586 | + if ($form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
587 | + || $form_config === FormHandler::ADD_FORM_TAGS_ONLY |
|
588 | + ) { |
|
589 | + $additional_props = $this->requiresMultipartEnctype() |
|
590 | + ? 'enctype="multipart/form-data"' |
|
591 | + : ''; |
|
592 | + $form_html .= $this->form()->form_open( |
|
593 | + $this->formAction(), |
|
594 | + 'POST', |
|
595 | + $additional_props |
|
596 | + ); |
|
597 | + } |
|
598 | + $form_html .= $this->form(true)->get_html(); |
|
599 | + if ($form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
600 | + || $form_config === FormHandler::ADD_FORM_TAGS_ONLY |
|
601 | + ) { |
|
602 | + $form_html .= $this->form()->form_close(); |
|
603 | + } |
|
604 | + $form_html .= apply_filters( |
|
605 | + 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__after_form', |
|
606 | + '' |
|
607 | + ); |
|
608 | + return $form_html; |
|
609 | + } |
|
610 | + |
|
611 | + /** |
|
612 | + * Determines if this form needs "enctype='multipart/form-data'" or not. |
|
613 | + * @since 4.9.80.p |
|
614 | + * @return bool |
|
615 | + * @throws EE_Error |
|
616 | + */ |
|
617 | + public function requiresMultipartEnctype() |
|
618 | + { |
|
619 | + foreach ($this->form()->inputs_in_subsections() as $input) { |
|
620 | + if ($input instanceof EE_File_Input) { |
|
621 | + return true; |
|
622 | + } |
|
623 | + } |
|
624 | + return false; |
|
625 | + } |
|
626 | + |
|
627 | + |
|
628 | + /** |
|
629 | + * handles processing the form submission |
|
630 | + * returns true or false depending on whether the form was processed successfully or not |
|
631 | + * |
|
632 | + * @param array $submitted_form_data |
|
633 | + * @return array |
|
634 | + * @throws \InvalidArgumentException |
|
635 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
636 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
637 | + * @throws EE_Error |
|
638 | + * @throws LogicException |
|
639 | + * @throws InvalidFormSubmissionException |
|
640 | + */ |
|
641 | + public function process($submitted_form_data = array()) |
|
642 | + { |
|
643 | + if (! $this->form()->was_submitted($submitted_form_data)) { |
|
644 | + throw new InvalidFormSubmissionException($this->form_name); |
|
645 | + } |
|
646 | + $this->form(true)->receive_form_submission($submitted_form_data); |
|
647 | + if (! $this->form()->is_valid()) { |
|
648 | + throw new InvalidFormSubmissionException( |
|
649 | + $this->form_name, |
|
650 | + sprintf( |
|
651 | + esc_html__( |
|
652 | + 'The "%1$s" form is invalid. Please correct the following errors and resubmit: %2$s %3$s', |
|
653 | + 'event_espresso' |
|
654 | + ), |
|
655 | + $this->form_name, |
|
656 | + '<br />', |
|
657 | + implode('<br />', $this->form()->get_validation_errors_accumulated()) |
|
658 | + ) |
|
659 | + ); |
|
660 | + } |
|
661 | + return apply_filters( |
|
662 | + 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__process__valid_data', |
|
663 | + $this->form()->valid_data(), |
|
664 | + $this |
|
665 | + ); |
|
666 | + } |
|
667 | 667 | } |
@@ -13,25 +13,25 @@ |
||
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 | } |