|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the fangface/yii2-concord package |
|
4
|
|
|
* |
|
5
|
|
|
* For the full copyright and license information, please view |
|
6
|
|
|
* the file LICENSE.md that was distributed with this source code. |
|
7
|
|
|
* |
|
8
|
|
|
* @package fangface/yii2-concord |
|
9
|
|
|
* @author Fangface <[email protected]> |
|
10
|
|
|
* @copyright Copyright (c) 2014 Fangface <[email protected]> |
|
11
|
|
|
* @license https://github.com/fangface/yii2-concord/blob/master/LICENSE.md MIT License |
|
12
|
|
|
* |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
namespace fangface\widgets; |
|
16
|
|
|
|
|
17
|
|
|
use fangface\base\traits\InputAddonTrait; |
|
18
|
|
|
use fangface\forms\ActiveForm; |
|
|
|
|
|
|
19
|
|
|
use fangface\forms\ActiveField; |
|
|
|
|
|
|
20
|
|
|
use fangface\widgets\WidgetTrait; |
|
21
|
|
|
use yii\widgets\ActiveField as YiiActiveField; |
|
22
|
|
|
use yii\widgets\InputWidget as YiiInputWidget; |
|
23
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Form Builder |
|
27
|
|
|
*/ |
|
28
|
|
|
class InputWidget extends YiiInputWidget |
|
29
|
|
|
{ |
|
30
|
|
|
use WidgetTrait; |
|
31
|
|
|
use InputAddonTrait; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var ActiveForm |
|
35
|
|
|
*/ |
|
36
|
|
|
public $form; |
|
37
|
|
|
/** |
|
38
|
|
|
* @var boolean is the input disabled, can be used to prevent registered assets for example |
|
39
|
|
|
*/ |
|
40
|
|
|
public $disabled = false; |
|
41
|
|
|
/** |
|
42
|
|
|
* @var array the HTML attributes for the input tag. |
|
43
|
|
|
*/ |
|
44
|
|
|
public $options = ['class' => 'form-control']; |
|
45
|
|
|
|
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* {@inheritDoc} |
|
49
|
|
|
* @see \yii\base\Widget::run() |
|
50
|
|
|
*/ |
|
51
|
|
|
public function run() |
|
52
|
|
|
{ |
|
53
|
|
|
if (isset($this->options['disabled'])) { |
|
54
|
|
|
$this->disabled = true; |
|
55
|
|
|
} |
|
56
|
|
|
$this->applyPluginSettings(); |
|
57
|
|
|
parent::run(); |
|
58
|
|
|
if (method_exists($this, 'renderWidget')) { |
|
59
|
|
|
$this->renderWidget(); |
|
|
|
|
|
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Prepare the template |
|
65
|
|
|
*/ |
|
66
|
|
|
public function prepareTemplate() |
|
67
|
|
|
{ |
|
68
|
|
|
$this->template = strtr($this->template, [ |
|
69
|
|
|
'{input}' => $this->generateAddon(), |
|
70
|
|
|
]); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Renders all sections using the current template [[template]]. |
|
75
|
|
|
* @return string the full rendering result |
|
76
|
|
|
*/ |
|
77
|
|
|
protected function renderTemplate() |
|
78
|
|
|
{ |
|
79
|
|
|
return $this->findSectionsToRender($this->template); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
} |
Let’s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let’s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: