CMSNicetiesTraitForReadOnly   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 17
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A makeReadonOnlyForCMSFields() 0 7 2
A makeReadonOnlyForCMSFieldsAll() 0 4 2
1
<?php
2
3
namespace Sunnysideup\CMSNiceties\Traits;
4
5
use SilverStripe\Forms\FieldList;
6
7
// use SilverStripe\Forms\GridField\GridFieldArchiveAction;
8
9
trait CMSNicetiesTraitForReadOnly
10
{
11
    protected function makeReadonOnlyForCMSFields(FieldList $fields, string $fieldName)
12
    {
13
        $field = $fields->dataFieldByName($fieldName);
14
        if ($field) {
15
            $fields->replaceField(
16
                $fieldName,
17
                $field->performReadonlyTransformation()
18
            );
19
        }
20
    }
21
22
    protected function makeReadonOnlyForCMSFieldsAll(FieldList $fields, array $arrayOfFields)
23
    {
24
        foreach ($arrayOfFields as $fieldName) {
25
            $this->makeReadonOnlyForCMSFields($fields, $fieldName);
26
        }
27
    }
28
}
29