1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Riclep\StoryblokForms; |
4
|
|
|
|
5
|
|
|
use Riclep\StoryblokForms\Blocks\LsfFieldset; |
6
|
|
|
use Riclep\StoryblokForms\Blocks\LsfRepeatingFieldset; |
7
|
|
|
use Riclep\StoryblokForms\Traits\ToJson; |
8
|
|
|
|
9
|
|
|
class Input extends \Riclep\Storyblok\Block |
10
|
|
|
{ |
11
|
|
|
use ToJson; |
12
|
|
|
|
13
|
|
|
protected $inFieldSet = false; |
14
|
|
|
protected $isRepeating = false; |
15
|
|
|
protected $key; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var string[] All the Validators for this Input |
19
|
|
|
*/ |
20
|
|
|
protected $_casts = ['validators' => Validators::class]; |
21
|
|
|
|
22
|
|
|
public function __construct($content, $parent = null) |
23
|
|
|
{ |
24
|
|
|
parent::__construct($content, $parent); |
25
|
|
|
|
26
|
|
|
if ($this->parent() instanceof LsfFieldset) { |
27
|
|
|
$this->inFieldSet = true; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
if ($this->parent() instanceof LsfRepeatingFieldset) { |
31
|
|
|
$this->isRepeating = true; |
32
|
|
|
} |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function getInputNameAttribute() { |
36
|
|
|
if ($this->isRepeating) { |
37
|
|
|
return $this->parent()->input_name . '[' . $this->key . '][' . $this->content()['name'] . ']'; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
if ($this->inFieldSet) { |
41
|
|
|
return $this->parent()->input_name . '[' . $this->content()['name'] . ']'; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
return $this->content()['name']; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
public function loopKey($key) { |
49
|
|
|
$this->key = $key; |
50
|
|
|
|
51
|
|
|
return $this; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* All the Validation rules for this Input |
57
|
|
|
* |
58
|
|
|
* @return mixed |
59
|
|
|
*/ |
60
|
|
|
public function validationRules() { |
61
|
|
|
return $this->validators->validationRules(); |
|
|
|
|
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* All the error messages for this Input |
66
|
|
|
* |
67
|
|
|
* @return mixed |
68
|
|
|
*/ |
69
|
|
|
public function errorMessages() { |
70
|
|
|
return $this->validators->errorMessages(); |
|
|
|
|
71
|
|
|
} |
72
|
|
|
} |