PluginProbe
Packeta / 1.6.4
Packeta v1.6.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.6.4, at src/Packetery/Module/FormFactory.php

71 lines 1.7 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 Packetery\Nette\Forms\Form;
13 use Packetery\Nette\Forms\Validator;
14 use Packetery\Nette\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
44 Validator::$messages[ Form::INTEGER ] = __( 'Enter valid number', 'packeta' );
45 Validator::$messages[ Form::FLOAT ] = __( 'Enter valid number', 'packeta' );
46 Validator::$messages[ Form::FILLED ] = __( 'This field is required', 'packeta' );
47 // translators: %d is number of characters.
48 Validator::$messages[ Form::LENGTH ] = __( 'Please enter exactly %d characters', 'packeta' );
49 // translators: %d is number of characters.
50 Validator::$messages[ Form::MAX_LENGTH ] = __( 'Please enter max %d characters', 'packeta' );
51 },
52 11
53 );
54 $this->request = $request;
55 }
56
57 /**
58 * Creates Form
59 *
60 * @param string|null $name Form name.
61 *
62 * @return Form
63 */
64 public function create( ?string $name = null ): Form {
65 $form = new Form( $name );
66 $form->setHttpRequest( $this->request );
67 $form->allowCrossOrigin();
68 return $form;
69 }
70 }
71