Completed
Pull Request — master (#1350)
by
unknown
03:06
created

Icon::placement()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Encore\Admin\Form\Field;
4
5
class Icon extends Text
6
{
7
    protected $default = 'fa-pencil';
8
9
    protected static $css = [
10
        '/vendor/laravel-admin/fontawesome-iconpicker/dist/css/fontawesome-iconpicker.min.css',
11
    ];
12
13
    protected static $js = [
14
        '/vendor/laravel-admin/fontawesome-iconpicker/dist/js/fontawesome-iconpicker.min.js',
15
    ];
16
17
    public function __construct($column, array $arguments = [])
18
    {
19
        parent::__construct($column, $arguments);
20
        $this->options(['placement' => 'bottomLeft']);
21
22
    }
23
24
    /**
25
     * Set placement setting of iconpicker.
26
     * second word must be upper case
27
     * example bottomLeft or bottomRight
28
     *
29
     * @param string $placement
30
     *
31
     * @return $this
32
     */
33
    public function placement($placement)
34
    {
35
        $this->options(['placement' => $placement]);
36
        return $this;
37
    }
38
39
    public function render()
40
    {
41
42
        $startOptions = json_encode($this->options);
43
44
        $this->script = <<<EOT
45
46
$('{$this->getElementClassSelector()}').iconpicker($startOptions);
47
48
EOT;
49
50
        $this->prepend('<i class="fa fa-pencil"></i>')
51
            ->defaultAttribute('style', 'width: 140px');
52
53
        return parent::render();
0 ignored issues
show
Bug Compatibility introduced by
The expression parent::render(); of type Illuminate\Contracts\Vie...ry|Illuminate\View\View adds the type Illuminate\Contracts\View\Factory to the return on line 53 which is incompatible with the return type declared by the interface Illuminate\Contracts\Support\Renderable::render of type string.
Loading history...
54
    }
55
}
56