1 | <?php |
||
14 | class GroupActionCollection extends Nette\Object |
||
15 | { |
||
16 | |||
17 | const ID_ATTRIBUTE_PREFIX = 'group_action_item_'; |
||
18 | |||
19 | /** |
||
20 | * @var GroupAction[] |
||
21 | */ |
||
22 | protected $group_actions = []; |
||
23 | |||
24 | /** |
||
25 | * Get assambled form |
||
26 | * @param Nette\Forms\Container $container |
||
27 | * @return void |
||
28 | */ |
||
29 | public function addToFormContainer($container) |
||
30 | { |
||
31 | /** @var Nette\Application\UI\Form $form */ |
||
32 | $form = $container->lookup('Nette\Application\UI\Form'); |
||
33 | $translator = $form->getTranslator(); |
||
34 | $main_options = []; |
||
35 | |||
36 | /** |
||
37 | * First foreach for filling "main" select |
||
38 | */ |
||
39 | foreach ($this->group_actions as $id => $action) { |
||
40 | $main_options[$id] = $action->getTitle(); |
||
41 | } |
||
42 | |||
43 | $container->addSelect('group_action', '', $main_options) |
||
44 | ->setPrompt($translator->translate('ublaboo_datagrid.choose')); |
||
45 | |||
46 | /** |
||
47 | * Second for creating select for each "sub"-action |
||
48 | */ |
||
49 | foreach ($this->group_actions as $id => $action) { |
||
50 | if ($action instanceof GroupSelectAction) { |
||
51 | if ($action->hasOptions()) { |
||
52 | $container->addSelect($id, '', $action->getOptions()) |
||
53 | ->setAttribute('id', static::ID_ATTRIBUTE_PREFIX . $id); |
||
|
|||
54 | } |
||
55 | } else if ($action instanceof GroupTextAction) { |
||
56 | $container->addText($id, '') |
||
57 | ->setAttribute('id', static::ID_ATTRIBUTE_PREFIX . $id) |
||
58 | ->addConditionOn($container['group_action'], Form::EQUAL, $id) |
||
59 | ->setRequired($translator->translate('ublaboo_datagrid.choose_input_required')); |
||
60 | } |
||
61 | } |
||
62 | |||
63 | foreach ($this->group_actions as $id => $action) { |
||
64 | $container['group_action']->addCondition(Form::EQUAL, $id) |
||
65 | ->toggle(static::ID_ATTRIBUTE_PREFIX.$id); |
||
66 | } |
||
67 | |||
68 | $container['group_action']->addCondition(Form::FILLED) |
||
69 | ->toggle('group_action_submit'); |
||
70 | |||
71 | $container->addSubmit('submit', $translator->translate('ublaboo_datagrid.execute')) |
||
72 | ->setAttribute('id', 'group_action_submit'); |
||
73 | |||
74 | if ($form instanceof Nette\ComponentModel\IComponent) { |
||
75 | $form->onSubmit[] = [$this, 'submitted']; |
||
76 | } |
||
77 | } |
||
78 | |||
79 | |||
80 | /** |
||
81 | * Pass "sub"-form submission forward to custom submit function |
||
82 | * @param Form $form |
||
83 | * @return void |
||
84 | */ |
||
85 | public function submitted(Form $form) |
||
109 | |||
110 | |||
111 | /** |
||
112 | * Add one group action (select box) to collection of actions |
||
113 | * |
||
114 | * @param string $title |
||
115 | * @param array $options |
||
116 | * |
||
117 | * @return GroupAction |
||
118 | */ |
||
119 | public function addGroupSelectAction($title, $options) |
||
125 | |||
126 | /** |
||
127 | * Add one group action (text input) to collection of actions |
||
128 | * |
||
129 | * @param string $title |
||
130 | * |
||
131 | * @return GroupAction |
||
132 | */ |
||
133 | public function addGroupTextAction($title) |
||
139 | |||
140 | } |
||
141 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: