-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathOptions.php
More file actions
97 lines (77 loc) · 1.78 KB
/
Options.php
File metadata and controls
97 lines (77 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
namespace Gregwar\Formidable\Fields;
/**
* Sourced options
*
* @author Grégoire Passault <g.passault@gmail.com>
*/
class Options extends Field
{
/**
* Source name
*/
protected $source;
/**
* Select field
*/
protected $parent;
/**
* Positioning of the options in the parent
*/
protected $position;
/**
* Saving pushed data
*/
protected $pushSave = array();
public function __sleep()
{
return array_merge(parent::__sleep(), array(
'source', 'parent', 'position', 'pushSave'
));
}
public function push($name, $value = null)
{
if ($name == 'source') {
$this->source = $value;
} else {
$this->pushSave[$name] = $value;
}
}
public function setParent($parent)
{
$this->parent = $parent;
if (null === $this->position) {
$this->position = $this->parent->countOptions();
}
}
public function getParent()
{
return $this->parent;
}
public function check()
{
return;
}
public function getSource()
{
return $this->source;
}
public function source($options)
{
$toAdd = array();
foreach ($options as $key => $label) {
if (is_object($label)) {
$key = $label->getKey();
$label = $label->getValue();
}
$option = new Option();
foreach ($this->pushSave as $name => $value) {
$option->push($name, $value);
}
$option->setValue($key);
$option->setLabel($label);
$toAdd[] = $option;
}
$this->parent->addOptions($toAdd, $this->position);
}
}