1 | <?php |
||
2 | |||
3 | namespace DNADesign\Elemental\Forms; |
||
4 | |||
5 | use SilverStripe\Forms\CheckboxField; |
||
6 | use SilverStripe\Forms\CompositeField; |
||
7 | use SilverStripe\Forms\LiteralField; |
||
8 | use SilverStripe\Forms\TextField; |
||
9 | |||
10 | class TextCheckboxGroupField extends CompositeField |
||
11 | { |
||
12 | protected $schemaComponent = 'TextCheckboxGroupField'; |
||
13 | |||
14 | /** |
||
15 | * Set the composite's title to that of the first child |
||
16 | * |
||
17 | * @param string|null $title |
||
18 | */ |
||
19 | public function __construct($title = null) |
||
20 | { |
||
21 | if (!$title) { |
||
22 | $title = _t(__CLASS__ . '.Title', 'Title'); |
||
23 | } |
||
24 | |||
25 | $fields = [ |
||
26 | TextField::create('Title', $title), |
||
27 | CheckboxField::create('ShowTitle', _t(__CLASS__ . '.ShowTitleLabel', 'Displayed')) |
||
28 | ]; |
||
29 | |||
30 | parent::__construct($fields); |
||
31 | |||
32 | $this->setTitle($title); |
||
33 | } |
||
34 | |||
35 | /** |
||
36 | * Don't use the custom template for readonly states |
||
37 | * |
||
38 | * {@inheritDoc} |
||
39 | */ |
||
40 | public function performReadonlyTransformation() |
||
41 | { |
||
42 | $field = $this; |
||
43 | |||
44 | if (!$this->readonly) { |
||
45 | $field = parent::performReadonlyTransformation(); |
||
46 | |||
47 | $field->setTemplate(CompositeField::class); |
||
48 | $field->setTitle('Title'); |
||
49 | |||
50 | $titleField = $field->fieldByName('Title'); |
||
0 ignored issues
–
show
|
|||
51 | if ($titleField) { |
||
0 ignored issues
–
show
|
|||
52 | $field->replaceField('Title', LiteralField::create( |
||
53 | 'Title', |
||
54 | $titleField->Value() |
||
55 | )); |
||
56 | } |
||
57 | |||
58 | $displayedText = _t(__CLASS__ . '.DISPLAYED', 'Displayed'); |
||
59 | $notDisplayedText = _t(__CLASS__ . '.NOT_DISPLAYED', 'Not displayed'); |
||
60 | $showTitle = $field->fieldByName('ShowTitle'); |
||
0 ignored issues
–
show
Are you sure the assignment to
$showTitle is correct as $field->fieldByName('ShowTitle') targeting SilverStripe\Forms\CompositeField::fieldByName() seems to always return null.
This check looks for function or method calls that always return null and whose return value is assigned to a variable. class A
{
function getObject()
{
return null;
}
}
$a = new A();
$object = $a->getObject();
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. ![]() |
|||
61 | if ($showTitle) { |
||
0 ignored issues
–
show
|
|||
62 | $field->replaceField('ShowTitle', LiteralField::create( |
||
63 | 'ShowTitle', |
||
64 | $showTitle->Value() === 'Yes' ? $displayedText : $notDisplayedText |
||
65 | )->addExtraClass('show-title')); |
||
66 | } |
||
67 | } |
||
68 | |||
69 | return $field; |
||
70 | } |
||
71 | } |
||
72 |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()
can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.