Completed
Push — master ( eaf16e...6f8e07 )
by Mohamed
11:01
created

Moo_EditableFieldText::getFieldConfiguration()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 10
cts 10
cp 1
rs 9.2
c 0
b 0
f 0
cc 4
eloc 9
nc 8
nop 0
crap 4
1
<?php
2
3
/**
4
 * Moo_EditableFieldText is an object representing text field created by CMS admin.
5
 *
6
 * @package editablefield
7
 *
8
 * @author  Mohamed Alsharaf <[email protected]>
9
 */
10
class Moo_EditableFieldText extends Moo_EditableField
11
{
12
    private static $singular_name   = 'Text Field';
13
    private static $plural_name     = 'Text Fields';
14
    protected $customSettingsFields = [
15
        'MinLength', 'MaxLength', 'Rows',
16
    ];
17
18 1
    public function getFieldConfiguration()
19
    {
20 1
        $min = ($this->getSetting('MinLength')) ? $this->getSetting('MinLength') : '';
21 1
        $max = ($this->getSetting('MaxLength')) ? $this->getSetting('MaxLength') : '';
22
23 1
        $rows = ($this->getSetting('Rows')) ? $this->getSetting('Rows') : '1';
24
25
        return [
26 1
            $learnMoreField = FieldGroup::create(_t('Moo_EditableFieldText.TEXTLENGTH', 'Text length'),
27 1
                new NumericField($this->getSettingName('MinLength'), 'Min', $min),
28 1
                new NumericField($this->getSettingName('MaxLength'), 'Max', $max)
29 1
            ),
30 1
            new NumericField($this->getSettingName('Rows'), _t('Moo_EditableFieldText.NUMBERROWS', 'Number of rows'), $rows),
31 1
        ];
32
    }
33
34
    /**
35
     * @return TextareaField|TextField
36
     */
37 1
    protected function initFormField()
38
    {
39 1
        if ($this->getSetting('Rows') && $this->getSetting('Rows') > 1) {
40 1
            $taf = new TextareaField($this->Name, $this->Title);
41 1
            $taf->setRows($this->getSetting('Rows'));
42
43 1
            return $taf;
44
        } else {
45 1
            return new TextField($this->Name, $this->Title, null, $this->getSetting('MaxLength'));
46
        }
47
    }
48
}
49