Passed
Push — master ( 9503af...0b2a3d )
by Bruno
05:22
created

Renderable_associationAutocomplete::viewable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 3
1
<?php declare(strict_types=1);
2
3
namespace Modelarium\Frontend\Vue\Renderable;
4
5
use Formularium\Datatype;
6
use Formularium\Field;
7
use Formularium\Frontend\HTML\Framework;
8
use Formularium\HTMLElement;
9
10
class Renderable_associationAutocomplete extends Renderable_relationship
11
{
12
    public function viewable($value, Field $field, HTMLElement $previous): HTMLElement
13
    {
14
        return $previous;
15
    }
16
17
    public function editable($value, Field $field, HTMLElement $previous): HTMLElement
18
    {
19
        $input = new HTMLElement('input');
20
    
21
        $renderable = $field->getRenderables();
22
        $validators = $field->getValidators();
23
        $input->setAttributes([
24
                'id' => $field->getName() . Framework::counter(),
25
                'name' => $field->getName(),
26
                'class' => '',
27
                'data-attribute' => $field->getName(),
28
                'data-datatype' => $field->getDatatype()->getName(),
29
                'data-basetype' => $field->getDatatype()->getBasetype(),
30
                'title' => $field->getRenderable(static::LABEL, ''),
31
                'autocomplete' => 'off'
32
            ]);
33
    
34
        if (isset($renderable[static::PLACEHOLDER])) {
35
            $input->setAttribute('placeholder', $renderable[static::PLACEHOLDER]);
36
        }
37
        if ($validators[Datatype::REQUIRED] ?? false) {
38
            $input->setAttribute('required', 'required');
39
        }
40
        foreach ([static::DISABLED, static::READONLY] as $v) {
41
            if ($field->getRenderable($v, false)) {
42
                $input->setAttribute($v, $v);
43
            }
44
        }
45
    
46
        return $this->container($input, $field);
47
    }
48
}
49