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

Moo_EditableFieldText   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 5
dl 0
loc 39
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getFieldConfiguration() 0 15 4
A initFormField() 0 11 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
    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