|
1
|
|
|
<?php |
|
2
|
|
|
namespace Sirius\Input\Element; |
|
3
|
|
|
|
|
4
|
|
|
use Sirius\Input\Traits\HasChildrenTrait; |
|
5
|
|
|
use Sirius\Input\Traits\HasLabelTrait; |
|
6
|
|
|
use Sirius\Input\Traits\HasHintTrait; |
|
7
|
|
|
use Sirius\Input\Traits\HasFiltersTrait; |
|
8
|
|
|
use Sirius\Input\Traits\HasValidationRulesTrait; |
|
9
|
|
|
use Sirius\Input\Element\Factory as ElementFactory; |
|
10
|
|
|
use Sirius\Input\Element\FactoryAwareInterface as ElementFactoryAwareInterface; |
|
11
|
|
|
use Sirius\Input\InputFilter; |
|
12
|
|
|
use Sirius\Input\Specs; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* A fielset is a special kind of input element that has a namespace |
|
16
|
|
|
* If a fielset contains an address its name will be `address` and will contain |
|
17
|
|
|
* children like `street_name`, `city`, `zip_code` etc. |
|
18
|
|
|
* Children will be rendered as `address[street_name]`, `address[city]` etc |
|
19
|
|
|
*/ |
|
20
|
|
|
class Fieldset extends Input implements ElementFactoryAwareInterface |
|
21
|
|
|
{ |
|
22
|
|
|
use HasChildrenTrait; |
|
23
|
|
|
use HasLabelTrait; |
|
24
|
|
|
use HasHintTrait; |
|
25
|
|
|
use HasFiltersTrait; |
|
26
|
|
|
use HasValidationRulesTrait; |
|
27
|
|
|
|
|
28
|
5 |
|
protected function getDefaultSpecs() |
|
29
|
|
|
{ |
|
30
|
|
|
return array( |
|
31
|
5 |
|
Specs::WIDGET => 'fieldset' |
|
32
|
5 |
|
); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Generate the namespaced field name of an element inside the fieldset |
|
37
|
|
|
* |
|
38
|
|
|
* @param string $name |
|
39
|
|
|
* |
|
40
|
|
|
* @return string |
|
41
|
|
|
*/ |
|
42
|
5 |
|
protected function getFullChildName($name) |
|
43
|
|
|
{ |
|
44
|
5 |
|
$firstOpenBracket = strpos($name, '['); |
|
45
|
|
|
// the name is already at least 2 levels deep like street[name] |
|
46
|
5 |
|
if ($firstOpenBracket !== false) { |
|
47
|
1 |
|
$name = substr($name, 0, $firstOpenBracket) . '][' . substr($name, $firstOpenBracket + 1, - 1); |
|
48
|
1 |
|
} |
|
49
|
|
|
|
|
50
|
5 |
|
return $this->getName() . '[' . $name . ']'; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
1 |
|
public function prepareInputFilter(InputFilter $inputFilter) |
|
54
|
|
|
{ |
|
55
|
1 |
|
parent::prepareInputFilter($inputFilter); |
|
56
|
1 |
|
$this->cleanUpMissingGroups(); |
|
57
|
|
|
|
|
58
|
1 |
|
foreach ($this->getElements() as $element) { |
|
59
|
1 |
|
$element->prepareInputFilter($inputFilter); |
|
60
|
1 |
|
} |
|
61
|
1 |
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|