Issues (2882)

src/ORM/DataExtension.php (14 issues)

1
<?php
2
3
namespace SilverStripe\ORM;
4
5
use SilverStripe\Core\Config\Config;
6
use SilverStripe\Core\Extension;
7
use SilverStripe\Forms\FieldList;
8
use SilverStripe\ORM\Queries\SQLSelect;
9
use Exception;
10
11
/**
12
 * An extension that adds additional functionality to a {@link DataObject}.
13
 *
14
 * @property DataObject $owner
15
 */
16
abstract class DataExtension extends Extension
17
{
18
19
    public static function unload_extra_statics($class, $extension)
0 ignored issues
show
The parameter $extension is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

19
    public static function unload_extra_statics($class, /** @scrutinizer ignore-unused */ $extension)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $class is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

19
    public static function unload_extra_statics(/** @scrutinizer ignore-unused */ $class, $extension)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
20
    {
21
        throw new Exception('unload_extra_statics gone');
22
    }
23
24
    /**
25
     * Hook for extension-specific validation.
26
     *
27
     * @param ValidationResult $validationResult Local validation result
28
     * @throws ValidationException
29
     */
30
    public function validate(ValidationResult $validationResult)
0 ignored issues
show
The parameter $validationResult is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

30
    public function validate(/** @scrutinizer ignore-unused */ ValidationResult $validationResult)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
31
    {
32
    }
33
34
    /**
35
     * Edit the given query object to support queries for this extension
36
     *
37
     * @param SQLSelect $query Query to augment.
38
     * @param DataQuery $dataQuery Container DataQuery for this SQLSelect
39
     */
40
    public function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null)
0 ignored issues
show
The parameter $dataQuery is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

40
    public function augmentSQL(SQLSelect $query, /** @scrutinizer ignore-unused */ DataQuery $dataQuery = null)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $query is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

40
    public function augmentSQL(/** @scrutinizer ignore-unused */ SQLSelect $query, DataQuery $dataQuery = null)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
41
    {
42
    }
43
44
    /**
45
     * Update the database schema as required by this extension.
46
     *
47
     * When duplicating a table's structure, remember to duplicate the create options
48
     * as well. See {@link Versioned->augmentDatabase} for an example.
49
     */
50
    public function augmentDatabase()
51
    {
52
    }
53
54
    /**
55
     * Augment a write-record request.
56
     *
57
     * @param array $manipulation Array of operations to augment.
58
     */
59
    public function augmentWrite(&$manipulation)
0 ignored issues
show
The parameter $manipulation is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

59
    public function augmentWrite(/** @scrutinizer ignore-unused */ &$manipulation)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
60
    {
61
    }
62
63
    public function onBeforeWrite()
64
    {
65
    }
66
67
    public function onAfterWrite()
68
    {
69
    }
70
71
    public function onBeforeDelete()
72
    {
73
    }
74
75
    public function onAfterDelete()
76
    {
77
    }
78
79
    public function requireDefaultRecords()
80
    {
81
    }
82
83
    public function populateDefaults()
84
    {
85
    }
86
87
    public function can($member)
0 ignored issues
show
The parameter $member is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

87
    public function can(/** @scrutinizer ignore-unused */ $member)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
88
    {
89
    }
90
91
    public function canEdit($member)
0 ignored issues
show
The parameter $member is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

91
    public function canEdit(/** @scrutinizer ignore-unused */ $member)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
92
    {
93
    }
94
95
    public function canDelete($member)
0 ignored issues
show
The parameter $member is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

95
    public function canDelete(/** @scrutinizer ignore-unused */ $member)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
96
    {
97
    }
98
99
    public function canCreate($member)
0 ignored issues
show
The parameter $member is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

99
    public function canCreate(/** @scrutinizer ignore-unused */ $member)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
100
    {
101
    }
102
103
    /**
104
     * Define extra database fields
105
     *
106
     * Return a map where the keys are db, has_one, etc, and the values are
107
     * additional fields/relations to be defined.
108
     *
109
     * @param string $class since this method might be called on the class directly
110
     * @param string $extension since this can help to extract parameters to help set indexes
111
     * @return array Returns a map where the keys are db, has_one, etc, and
112
     *               the values are additional fields/relations to be defined.
113
     */
114
    public function extraStatics($class = null, $extension = null)
0 ignored issues
show
The parameter $class is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

114
    public function extraStatics(/** @scrutinizer ignore-unused */ $class = null, $extension = null)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $extension is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

114
    public function extraStatics($class = null, /** @scrutinizer ignore-unused */ $extension = null)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
115
    {
116
        return array();
117
    }
118
119
    /**
120
     * This function is used to provide modifications to the form in the CMS
121
     * by the extension. By default, no changes are made. {@link DataObject->getCMSFields()}.
122
     *
123
     * Please consider using {@link updateFormFields()} to globally add
124
     * formfields to the record. The method {@link updateCMSFields()}
125
     * should just be used to add or modify tabs, or fields which
126
     * are specific to the CMS-context.
127
     *
128
     * Caution: Use {@link FieldList->addFieldToTab()} to add fields.
129
     *
130
     * @param FieldList $fields FieldList with a contained TabSet
131
     */
132
    public function updateCMSFields(FieldList $fields)
133
    {
134
    }
135
136
    /**
137
     * This function is used to provide modifications to the form used
138
     * for front end forms. {@link DataObject->getFrontEndFields()}
139
     *
140
     * Caution: Use {@link FieldList->push()} to add fields.
141
     *
142
     * @param FieldList $fields FieldList without TabSet nesting
143
     */
144
    public function updateFrontEndFields(FieldList $fields)
0 ignored issues
show
The parameter $fields is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

144
    public function updateFrontEndFields(/** @scrutinizer ignore-unused */ FieldList $fields)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
145
    {
146
    }
147
148
    /**
149
     * This is used to provide modifications to the form actions
150
     * used in the CMS. {@link DataObject->getCMSActions()}.
151
     *
152
     * @param FieldList $actions FieldList
153
     */
154
    public function updateCMSActions(FieldList $actions)
0 ignored issues
show
The parameter $actions is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

154
    public function updateCMSActions(/** @scrutinizer ignore-unused */ FieldList $actions)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
155
    {
156
    }
157
158
    /**
159
     * this function is used to provide modifications to the summary fields in CMS
160
     * by the extension
161
     * By default, the summaryField() of its owner will merge more fields defined in the extension's
162
     * $extra_fields['summary_fields']
163
     *
164
     * @param array $fields Array of field names
165
     */
166
    public function updateSummaryFields(&$fields)
167
    {
168
        $summary_fields = Config::inst()->get(static::class, 'summary_fields');
169
        if ($summary_fields) {
170
            // if summary_fields were passed in numeric array,
171
            // convert to an associative array
172
            if ($summary_fields && array_key_exists(0, $summary_fields)) {
173
                $summary_fields = array_combine(array_values($summary_fields), array_values($summary_fields));
174
            }
175
            if ($summary_fields) {
176
                $fields = array_merge($fields, $summary_fields);
177
            }
178
        }
179
    }
180
181
    /**
182
     * this function is used to provide modifications to the fields labels in CMS
183
     * by the extension
184
     * By default, the fieldLabels() of its owner will merge more fields defined in the extension's
185
     * $extra_fields['field_labels']
186
     *
187
     * @param array $labels Array of field labels
188
     */
189
    public function updateFieldLabels(&$labels)
190
    {
191
        $field_labels = Config::inst()->get(static::class, 'field_labels');
192
        if ($field_labels) {
193
            $labels = array_merge($labels, $field_labels);
194
        }
195
    }
196
}
197