|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Components\Forms; |
|
4
|
|
|
|
|
5
|
|
|
use App\Components\BaseControl; |
|
6
|
|
|
use Nette\Application\UI\Form; |
|
7
|
|
|
use Nette\Forms\Controls; |
|
8
|
|
|
|
|
9
|
|
|
abstract class BaseForm extends BaseControl |
|
10
|
|
|
{ |
|
11
|
|
|
|
|
12
|
|
|
const TEMPLATE_DIR = __DIR__ . '/../../templates/components/Forms'; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @param Form $form |
|
16
|
|
|
* @return Form |
|
17
|
|
|
*/ |
|
18
|
|
|
protected function setupRendering(Form $form): Form |
|
19
|
|
|
{ |
|
20
|
|
|
// setup form rendering |
|
21
|
|
|
$renderer = $form->getRenderer(); |
|
22
|
|
|
$renderer->wrappers['controls']['container'] = NULL; |
|
|
|
|
|
|
23
|
|
|
$renderer->wrappers['pair']['.error'] = 'has-error'; |
|
|
|
|
|
|
24
|
|
|
$renderer->wrappers['control']['description'] = 'span class=help-block'; |
|
|
|
|
|
|
25
|
|
|
$renderer->wrappers['control']['errorcontainer'] = 'span class=help-block'; |
|
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
// make form and controls compatible with Twitter Bootstrap |
|
28
|
|
|
$form->getElementPrototype()->class('form-horizontal'); |
|
29
|
|
|
foreach ($form->getControls() as $control) { |
|
30
|
|
|
if ($control instanceof Controls\Button) { |
|
31
|
|
|
$control->getControlPrototype() |
|
32
|
|
|
->addClass(empty($usedPrimary) ? 'btn btn-default' : ''); |
|
33
|
|
|
$usedPrimary = TRUE; |
|
34
|
|
|
} elseif ( |
|
35
|
|
|
$control instanceof Controls\TextBase || |
|
36
|
|
|
$control instanceof Controls\SelectBox || |
|
37
|
|
|
$control instanceof Controls\MultiSelectBox |
|
38
|
|
|
) { |
|
39
|
|
|
$control->getControlPrototype() |
|
40
|
|
|
->addClass('form-control'); |
|
41
|
|
|
} elseif ( |
|
42
|
|
|
$control instanceof Controls\Checkbox || |
|
43
|
|
|
$control instanceof Controls\CheckboxList || |
|
44
|
|
|
$control instanceof Controls\RadioList |
|
45
|
|
|
) { |
|
46
|
|
|
$control->getSeparatorPrototype() |
|
47
|
|
|
->setName('div') |
|
48
|
|
|
->addClass($control->getControlPrototype()->type); |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
return $form; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
} |
|
56
|
|
|
|
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: