EditableRadioField::getSelectorField()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 2
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace SilverStripe\UserForms\Model\EditableFormField;
4
5
use SilverStripe\Forms\OptionsetField;
6
use SilverStripe\UserForms\Model\EditableCustomRule;
7
8
/**
9
 * EditableRadioField
10
 *
11
 * Represents a set of selectable radio buttons
12
 *
13
 * @package userforms
14
 */
15
16
class EditableRadioField extends EditableMultipleOptionField
17
{
18
    private static $singular_name = 'Radio Group';
0 ignored issues
show
introduced by
The private property $singular_name is not used, and could be removed.
Loading history...
19
20
    private static $plural_name = 'Radio Groups';
0 ignored issues
show
introduced by
The private property $plural_name is not used, and could be removed.
Loading history...
21
22
    private static $table_name = 'EditableRadioField';
0 ignored issues
show
introduced by
The private property $table_name is not used, and could be removed.
Loading history...
23
24
    /**
25
     * @return FieldList
0 ignored issues
show
Bug introduced by
The type SilverStripe\UserForms\M...ableFormField\FieldList was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
26
     */
27
    public function getCMSFields()
28
    {
29
        $fields = parent::getCMSFields();
30
31
        $fields->removeByName('Default');
32
33
        return $fields;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $fields returns the type SilverStripe\Forms\FieldList which is incompatible with the documented return type SilverStripe\UserForms\M...ableFormField\FieldList.
Loading history...
34
    }
35
36
    public function getFormField()
37
    {
38
        $field = OptionsetField::create($this->Name, $this->Title ?: false, $this->getOptionsMap())
39
            ->setFieldHolderTemplate(EditableMultipleOptionField::class . '_holder')
40
            ->setTemplate('SilverStripe\\UserForms\\FormField\\UserFormsOptionSetField');
41
42
        // Set default item
43
        $defaultOption = $this->getDefaultOptions()->first();
44
        if ($defaultOption) {
45
            $field->setValue($defaultOption->Value);
46
        }
47
        $this->doUpdateFormField($field);
48
        return $field;
49
    }
50
51
    public function getSelectorField(EditableCustomRule $rule, $forOnLoad = false)
52
    {
53
        // We only want to trigger on load once for the radio group - hence we focus on the first option only.
54
        $first = $forOnLoad ? ':first' : '';
55
        return "$(\"input[name='{$this->Name}']{$first}\")";
56
    }
57
58
    public function isRadioField()
59
    {
60
        return true;
61
    }
62
}
63