|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* User: delboy1978uk |
|
4
|
|
|
* Date: 04/12/2016 |
|
5
|
|
|
* Time: 23:36 |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace Del\Form\Renderer\Error; |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
use Del\Form\Field\FieldInterface; |
|
12
|
|
|
use DOMElement; |
|
13
|
|
|
use DOMText; |
|
14
|
|
|
|
|
15
|
|
|
class HorizontalFormErrorRender extends AbstractErrorRender implements ErrorRendererInterface |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @param DOMElement $div |
|
|
|
|
|
|
19
|
|
|
* @param FieldInterface $field |
|
20
|
|
|
* @return DOMElement |
|
21
|
|
|
*/ |
|
22
|
1 |
|
public function render(FieldInterface $field) |
|
23
|
|
|
{ |
|
24
|
1 |
|
$helpBlock = $this->dom->createElement('span'); |
|
25
|
1 |
|
$helpBlock->setAttribute('class', 'help-block'); |
|
26
|
|
|
|
|
27
|
1 |
View Code Duplication |
if ($field->hasCustomErrorMessage()) { |
|
|
|
|
|
|
28
|
1 |
|
$helpBlock = $this->addCustomErrorMessage($helpBlock, $field); |
|
29
|
|
|
} else { |
|
30
|
1 |
|
$helpBlock = $this->addErrorMessages($helpBlock, $field); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
1 |
|
$div = $this->dom->createElement('div'); |
|
34
|
1 |
|
$div->setAttribute('class', 'col-sm-offset-2 col-sm-10'); |
|
35
|
1 |
|
$div->appendChild($helpBlock); |
|
36
|
1 |
|
return $div; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @param DOMElement $helpBlock |
|
41
|
|
|
* @param FieldInterface $field |
|
42
|
|
|
* @return DOMElement |
|
43
|
|
|
*/ |
|
44
|
1 |
View Code Duplication |
private function addCustomErrorMessage(DOMElement $helpBlock, FieldInterface $field) |
|
|
|
|
|
|
45
|
|
|
{ |
|
46
|
1 |
|
$message = $field->getCustomErrorMessage(); |
|
47
|
1 |
|
$text = new DOMText($message); |
|
48
|
1 |
|
$helpBlock->appendChild($text); |
|
49
|
1 |
|
return $helpBlock; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @param DOMElement $helpBlock |
|
54
|
|
|
* @param FieldInterface $field |
|
55
|
|
|
* @return DOMElement] |
|
|
|
|
|
|
56
|
|
|
*/ |
|
57
|
1 |
View Code Duplication |
private function addErrorMessages(DOMElement $helpBlock, FieldInterface $field) |
|
|
|
|
|
|
58
|
|
|
{ |
|
59
|
1 |
|
$messages = $field->getMessages(); |
|
60
|
|
|
|
|
61
|
1 |
|
foreach ($messages as $message) { |
|
62
|
1 |
|
$helpBlock = $this->appendMessage($helpBlock, $message); |
|
63
|
|
|
} |
|
64
|
1 |
|
return $helpBlock; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @param DOMElement $helpBlock |
|
69
|
|
|
* @param $message |
|
70
|
|
|
* @return DOMElement |
|
71
|
|
|
*/ |
|
72
|
1 |
View Code Duplication |
private function appendMessage(DOMElement $helpBlock, $message) |
|
|
|
|
|
|
73
|
|
|
{ |
|
74
|
1 |
|
$text = new DOMText($message); |
|
75
|
1 |
|
$br = $this->dom->createElement('br'); |
|
76
|
1 |
|
$helpBlock->appendChild($text); |
|
77
|
1 |
|
$helpBlock->appendChild($br); |
|
78
|
1 |
|
return $helpBlock; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
} |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.