| Conditions | 13 |
| Paths | 248 |
| Total Lines | 86 |
| Code Lines | 46 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 46 | public function addToFormContainer($container) |
||
| 47 | { |
||
| 48 | /** @var Nette\Application\UI\Form $form */ |
||
| 49 | $form = $container->lookup('Nette\Application\UI\Form'); |
||
| 50 | $translator = $form->getTranslator(); |
||
| 51 | $main_options = []; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * First foreach for filling "main" select |
||
| 55 | */ |
||
| 56 | foreach ($this->group_actions as $id => $action) { |
||
| 57 | $main_options[$id] = $action->getTitle(); |
||
| 58 | } |
||
| 59 | |||
| 60 | $container->addSelect('group_action', '', $main_options) |
||
| 61 | ->setPrompt('ublaboo_datagrid.choose'); |
||
| 62 | |||
| 63 | /** |
||
| 64 | * Second for creating select for each "sub"-action |
||
| 65 | */ |
||
| 66 | foreach ($this->group_actions as $id => $action) { |
||
| 67 | $control = null; |
||
| 68 | |||
| 69 | if ($action instanceof GroupSelectAction) { |
||
| 70 | if ($action->hasOptions()) { |
||
| 71 | if ($action instanceof GroupMultiSelectAction) { |
||
| 72 | $control = $container->addMultiSelect($id, '', $action->getOptions()); |
||
| 73 | $control->setAttribute('data-datagrid-multiselect-id', static::ID_ATTRIBUTE_PREFIX . $id); |
||
| 74 | $control->setAttribute('data-style', 'hidden'); |
||
| 75 | $control->setAttribute('data-selected-icon-check', DataGrid::$icon_prefix . 'check'); |
||
| 76 | } else { |
||
| 77 | $control = $container->addSelect($id, '', $action->getOptions()); |
||
| 78 | } |
||
| 79 | |||
| 80 | $control->setAttribute('id', static::ID_ATTRIBUTE_PREFIX . $id); |
||
| 81 | } |
||
| 82 | |||
| 83 | } elseif ($action instanceof GroupTextAction) { |
||
| 84 | $control = $container->addText($id, ''); |
||
| 85 | |||
| 86 | $control->setAttribute('id', static::ID_ATTRIBUTE_PREFIX . $id) |
||
| 87 | ->addConditionOn($container['group_action'], Form::EQUAL, $id) |
||
| 88 | ->setRequired($translator->translate('ublaboo_datagrid.choose_input_required')) |
||
| 89 | ->endCondition(); |
||
| 90 | |||
| 91 | } elseif ($action instanceof GroupTextareaAction) { |
||
| 92 | $control = $container->addTextarea($id, ''); |
||
| 93 | |||
| 94 | $control->setAttribute('id', static::ID_ATTRIBUTE_PREFIX . $id) |
||
| 95 | ->addConditionOn($container['group_action'], Form::EQUAL, $id) |
||
| 96 | ->setRequired($translator->translate('ublaboo_datagrid.choose_input_required')); |
||
| 97 | } |
||
| 98 | |||
| 99 | if ($control) { |
||
| 100 | /** |
||
| 101 | * User may set a class to the form control |
||
| 102 | */ |
||
| 103 | if ($class = $action->getClass()) { |
||
| 104 | $control->setAttribute('class', $class); |
||
| 105 | } |
||
| 106 | |||
| 107 | /** |
||
| 108 | * User may set additional attribtues to the form control |
||
| 109 | */ |
||
| 110 | foreach ($action->getAttributes() as $name => $value) { |
||
| 111 | $control->setAttribute($name, $value); |
||
| 112 | } |
||
| 113 | } |
||
| 114 | } |
||
| 115 | |||
| 116 | foreach ($this->group_actions as $id => $action) { |
||
| 117 | $container['group_action']->addCondition(Form::EQUAL, $id) |
||
| 118 | ->toggle(static::ID_ATTRIBUTE_PREFIX . $id); |
||
| 119 | } |
||
| 120 | |||
| 121 | $container['group_action']->addCondition(Form::FILLED) |
||
| 122 | ->toggle(strtolower($this->datagrid->getName()) . 'group_action_submit'); |
||
|
|
|||
| 123 | |||
| 124 | $container->addSubmit('submit', 'ublaboo_datagrid.execute') |
||
| 125 | ->setValidationScope([$container]) |
||
| 126 | ->setAttribute('id', strtolower($this->datagrid->getName()) . 'group_action_submit'); |
||
| 127 | |||
| 128 | if ($form instanceof Nette\ComponentModel\IComponent) { |
||
| 129 | $form->onSubmit[] = [$this, 'submitted']; |
||
| 130 | } |
||
| 131 | } |
||
| 132 | |||
| 242 |