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

Renderable_relationshipSelect   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 21
c 1
b 0
f 0
dl 0
loc 39
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A viewable() 0 3 1
A editable() 0 32 5
1
<?php declare(strict_types=1);
2
3
namespace Modelarium\Frontend\HTML\Renderable;
4
5
use Formularium\Datatype;
6
use Formularium\Field;
7
use Formularium\Frontend\HTML\Framework;
8
use Formularium\HTMLElement;
9
10
class Renderable_relationshipSelect 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('select');
20
    
21
        $renderable = $field->getRenderables();
22
        $input->setAttributes([
23
                'id' => $field->getName() . Framework::counter(),
24
                'name' => $field->getName(),
25
                'class' => '',
26
                'data-attribute' => $field->getName(),
27
                'data-datatype' => $field->getDatatype()->getName(),
28
                'data-basetype' => $field->getDatatype()->getBasetype(),
29
                'title' => $field->getRenderable(static::LABEL, ''),
30
                'autocomplete' => 'off'
31
            ]);
32
    
33
        if (isset($renderable[static::PLACEHOLDER])) {
34
            $input->setAttribute('placeholder', $renderable[static::PLACEHOLDER]);
35
        }
36
        if ($field->getValidatorOption(Datatype::REQUIRED)) {
37
            $input->setAttribute('required', 'required');
38
        }
39
        /* TODO if ($validators[Datatype_association::MULTIPLE] ?? false) {
40
            $input->setAttribute('multiple', 'multiple');
41
        } */
42
        foreach ([static::DISABLED, static::READONLY] as $v) {
43
            if ($field->getRenderable($v, false)) {
44
                $input->setAttribute($v, $v);
45
            }
46
        }
47
    
48
        return $this->container($input, $field);
49
    }
50
}
51