1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Riclep\StoryblokForms\Blocks; |
4
|
|
|
|
5
|
|
|
class LsfFieldset extends \Riclep\Storyblok\Block |
6
|
|
|
{ |
7
|
|
|
//// potentially all fields in a fieldset could be name <input name="fieldsetname[fieldname]"> |
8
|
|
|
/// this would out a multidimensional array in the response. |
9
|
|
|
/// makes validation herder? |
10
|
|
|
|
11
|
|
|
protected $inFieldSet = false; |
12
|
|
|
protected $isRepeating = false; |
13
|
|
|
|
14
|
|
|
public function __construct($content, $parent = null) |
15
|
|
|
{ |
16
|
|
|
parent::__construct($content, $parent); |
17
|
|
|
|
18
|
|
|
if ($this->parent() instanceof LsfFieldset) { |
19
|
|
|
$this->inFieldSet = true; |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
if ($this->parent() instanceof LsfRepeatingFieldset) { |
23
|
|
|
$this->isRepeating = true; |
24
|
|
|
} |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function getInputNameAttribute() { |
28
|
|
|
if ($this->isRepeating) { |
29
|
|
|
return $this->parent()->input_name . '[' . $this->key . '][' . $this->content()['name'] . ']'; |
|
|
|
|
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
if ($this->inFieldSet) { |
33
|
|
|
return $this->parent()->input_name . '[' . $this->content()['name'] . ']'; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
return $this->content()['name']; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Returns all the validation rules for the fields in this Fieldset |
42
|
|
|
* |
43
|
|
|
* @return array |
44
|
|
|
*/ |
45
|
|
|
public function validationRules() { |
46
|
|
|
$rules = []; |
47
|
|
|
|
48
|
|
|
$this->fields->each(function ($field) use (&$rules) { |
|
|
|
|
49
|
|
|
$rules = array_merge($rules, $field->validationRules()); |
50
|
|
|
}); |
51
|
|
|
|
52
|
|
|
return $rules; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Returns all the error messages for the fields in this Fieldset |
57
|
|
|
* |
58
|
|
|
* @return array |
59
|
|
|
*/ |
60
|
|
|
public function errorMessages() { |
61
|
|
|
$rules = []; |
62
|
|
|
|
63
|
|
|
$this->fields->each(function ($field) use (&$rules) { |
|
|
|
|
64
|
|
|
$rules = array_merge($rules, $field->errorMessages()); |
65
|
|
|
}); |
66
|
|
|
|
67
|
|
|
return $rules; |
68
|
|
|
} |
69
|
|
|
} |