Moo_EditableFieldText::initFormField()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 6
nc 2
nop 0
crap 3
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
15
    /**
16
     * List of allowed custom settings fields.
17
     *
18
     * @var array
19
     */
20
    protected $customSettingsFields = [
21
        'MinLength', 'MaxLength', 'Rows',
22
    ];
23
24
    /**
25
     * Get extra configuration fields.
26
     *
27
     * @return array
28
     */
29 1
    public function getFieldConfiguration()
30
    {
31 1
        $min = ($this->getSetting('MinLength')) ? $this->getSetting('MinLength') : '';
32 1
        $max = ($this->getSetting('MaxLength')) ? $this->getSetting('MaxLength') : '';
33
34 1
        $rows = ($this->getSetting('Rows')) ? $this->getSetting('Rows') : '1';
35
36
        return [
37 1
            $learnMoreField = FieldGroup::create(
38 1
                _t('Moo_EditableFieldText.TEXTLENGTH', 'Text length'),
39 1
                new NumericField($this->getSettingName('MinLength'), 'Min', $min),
40 1
                new NumericField($this->getSettingName('MaxLength'), 'Max', $max)
41 1
            ),
42 1
            new NumericField($this->getSettingName('Rows'), _t('Moo_EditableFieldText.NUMBERROWS', 'Number of rows'), $rows),
43 1
        ];
44
    }
45
46
    /**
47
     * @return TextareaField|TextField
48
     */
49 1
    protected function initFormField()
50
    {
51 1
        if ($this->getSetting('Rows') && $this->getSetting('Rows') > 1) {
52 1
            $textareaField = new TextareaField($this->Name, $this->Title);
53 1
            $textareaField->setRows($this->getSetting('Rows'));
54
55 1
            return $textareaField;
56
        }
57
58 1
        return new TextField($this->Name, $this->Title, null, $this->getSetting('MaxLength'));
59
    }
60
}
61