PluginProbe
Packeta / 1.4
Packeta v1.4
2.3.2 2.3.1 trunk 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3.0 1.3.1 1.3.2 1.4 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 All 56 releases
packeta / src / Packetery / Module / FormFactory.php

FormFactory.php in Packeta 1.4, at src/Packetery/Module/FormFactory.php

66 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Class FormFactory
4 *
5 * @package Packetery
6 */
7
8 declare( strict_types=1 );
9
10 namespace Packetery\Module;
11
12 use PacketeryNette\Forms\Form;
13 use PacketeryNette\Forms\Validator;
14 use PacketeryNette\Http\Request;
15
16 /**
17 * Class FormFactory
18 *
19 * @package Packetery
20 */
21 class FormFactory {
22
23 /**
24 * HTTP Request.
25 *
26 * @var Request
27 */
28 private $request;
29
30 /**
31 * Plugin constructor.
32 *
33 * @param Request $request HTTP request.
34 */
35 public function __construct( Request $request ) {
36 add_action(
37 'init',
38 function () {
39 // translators: keep %d placeholder intact.
40 Validator::$messages[ Form::MIN ] = __( 'Please enter value greater than or equal to %d', 'packeta' );
41 // translators: keep %d placeholder intact.
42 Validator::$messages[ Form::MAX ] = __( 'Please enter value less than or equal to %d', 'packeta' );
43 Validator::$messages[ Form::INTEGER ] = __( 'Enter valid number', 'packeta' );
44 Validator::$messages[ Form::FLOAT ] = __( 'Enter valid number', 'packeta' );
45 Validator::$messages[ Form::FILLED ] = __( 'This field is required', 'packeta' );
46 },
47 11
48 );
49 $this->request = $request;
50 }
51
52 /**
53 * Creates Form
54 *
55 * @param string|null $name Form name.
56 *
57 * @return Form
58 */
59 public function create( ?string $name = null ): Form {
60 $form = new Form( $name );
61 $form->setHttpRequest( $this->request );
62 $form->allowCrossOrigin();
63 return $form;
64 }
65 }
66