Completed
Push — master ( 90fbd0...297549 )
by Alexey
07:11
created

UploadAvatarForm::renderForm()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
c 0
b 0
f 0
dl 0
loc 14
rs 9.9666
cc 1
nc 1
nop 0
1
<?php
2
3
namespace modules\users\widgets;
4
5
use yii\base\Widget;
6
use yii\bootstrap\ActiveForm;
7
use yii\helpers\Url;
8
use yii\helpers\Html;
9
use modules\users\models\UploadForm;
10
use modules\users\Module;
11
12
/**
13
 * Class AvatarFormWidget
14
 * @package modules\users\widgets
15
 */
16
class UploadAvatarForm extends Widget
17
{
18
    /**
19
     * On/Off widget
20
     * @var bool
21
     */
22
    public $status = true;
23
    /**
24
     * @var UploadForm
25
     */
26
    public $model;
27
28
    /**
29
     * @inheritDoc
30
     */
31
    public function init()
32
    {
33
        parent::init();
34
        $this->model = $this->model ?: new UploadForm();
35
    }
36
37
    /**
38
     * @return string|void
39
     */
40
    public function run()
41
    {
42
        if ($this->status === true) {
43
            $this->renderForm();
44
        }
45
    }
46
47
    /**
48
     * Render upload form
49
     */
50
    public function renderForm()
51
    {
52
        $form = ActiveForm::begin([
53
            'action' => Url::to(['upload-image']),
54
            'options' => [
55
                'enctype' => 'multipart/form-data'
56
            ]
57
        ]);
58
        echo $form->field($this->model, 'imageFile')->fileInput();
59
        echo Html::submitButton('<span class="fa fa-upload"></span> ' . Module::t('module', 'Submit'), [
60
            'class' => 'btn btn-primary',
61
            'name' => 'submit-button',
62
        ]);
63
        ActiveForm::end();
64
    }
65
}
66