MultipleValue::setForm()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace kalanis\kw_table\form_kw\Fields;
4
5
6
use kalanis\kw_connect\core\Interfaces\IIterableConnector;
7
use kalanis\kw_forms\Exceptions\RenderException;
8
use kalanis\kw_forms\Form;
9
use kalanis\kw_table\core\Connector\AMultipleValue;
10
use kalanis\kw_table\core\TableException;
11
12
13
/**
14
 * Class MultipleValue
15
 * @package kalanis\kw_table\form_kw\Fields
16
 */
17
class MultipleValue extends AMultipleValue
18
{
19
    protected AField $field;
20
21 2
    public function __construct(AField $field, ?string $label = null, string $alias = '')
22
    {
23 2
        $this->field = $field;
24 2
        $this->alias = $alias;
25 2
        $this->label = $label;
26 2
    }
27
28 2
    public function getAlias(): string
29
    {
30 2
        return empty($this->alias)
31 1
            ? (empty($this->columnName)
32 1
                ? $this->field->getAlias() : $this->columnName)
33 2
            : $this->alias
34
        ;
35
    }
36
37 2
    public function getField(): AField
38
    {
39 2
        return $this->field;
40
    }
41
42 2
    public function setDataSourceConnector(IIterableConnector $dataSource): void
43
    {
44 2
        $this->field->setDataSourceConnector($dataSource);
45 2
    }
46
47 2
    public function setForm(Form $form): void
48
    {
49 2
        $this->field->setForm($form);
50 2
    }
51
52 2
    public function add(): void
53
    {
54 2
        $this->field->setAlias($this->getAlias());
55 2
        $this->field->add();
56 2
    }
57
58
    /**
59
     * @throws RenderException
60
     * @throws TableException
61
     * @return string
62
     */
63 2
    public function renderContent(): string
64
    {
65 2
        $control = $this->field->getFormInstance()->getControl($this->getAlias());
66 2
        $control->setLabel($this->getLabel());
67 2
        return $control->render();
68
    }
69
}
70