1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Riclep\StoryblokForms\Blocks; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Str; |
6
|
|
|
use Riclep\StoryblokForms\Input; |
7
|
|
|
|
8
|
|
|
class LsfInput extends Input |
9
|
|
|
{ |
10
|
|
|
// Interface this.... |
11
|
|
|
|
12
|
|
|
protected $type = 'input'; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* TODO - can this be moved into the validator and done at source? |
16
|
|
|
* |
17
|
|
|
* All the Validation rules for this Input |
18
|
|
|
* |
19
|
|
|
* @return mixed |
20
|
|
|
*/ |
21
|
|
|
public function validationRules() { |
22
|
|
|
$rules = $this->validators->validationRules(); |
|
|
|
|
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Rewrite required to required_if for items inside conditional selects |
26
|
|
|
*/ |
27
|
|
|
if ($this->parent() instanceof LsfConditionalSelect) { |
28
|
|
|
if (is_array($this->settings('lsf_is_conditional')['when_parent_is'])) { |
29
|
|
|
$requiredWhen = implode(',', $this->settings('lsf_is_conditional')['when_parent_is']); |
30
|
|
|
} else { |
31
|
|
|
$requiredWhen = $this->settings('lsf_is_conditional')['when_parent_is']; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
foreach ($rules as $key => $rule) { |
35
|
|
|
if (in_array('required', $rule)) { |
36
|
|
|
$requiredKey = array_search('required', $rule); |
37
|
|
|
|
38
|
|
|
$rules[$key][$requiredKey] = 'required_if:' . $this->parent()->input_dot_name . '.selected,' . $requiredWhen; |
|
|
|
|
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
return $rules; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* TODO - can this be moved into the validator and done at source? |
48
|
|
|
* |
49
|
|
|
* All the Validation rules for this Input |
50
|
|
|
* |
51
|
|
|
* @return mixed |
52
|
|
|
*/ |
53
|
|
|
public function errorMessages() { |
54
|
|
|
$messages = $this->validators->errorMessages(); |
|
|
|
|
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Rewrite required to required_if for items inside conditional selects |
58
|
|
|
*/ |
59
|
|
|
if ($this->parent() instanceof LsfConditionalSelect) { |
60
|
|
|
foreach ($messages as $key => $rule) { |
61
|
|
|
if (Str::endsWith($key, 'required')) { |
62
|
|
|
$messages[$key . '_if'] = $messages[$key]; |
63
|
|
|
|
64
|
|
|
unset($messages[$key]); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
return $messages; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Returns the Input’s response after the form has been submitted and validated |
74
|
|
|
* |
75
|
|
|
* @param $input |
76
|
|
|
* @return mixed |
77
|
|
|
*/ |
78
|
|
|
public function response($input) { |
79
|
|
|
return [ |
80
|
|
|
'label' => $this->label, |
|
|
|
|
81
|
|
|
'response' => $input, |
82
|
|
|
'type' => $this->type, |
83
|
|
|
]; |
84
|
|
|
} |
85
|
|
|
} |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.