@@ -81,6 +81,31 @@ class LinkerBehavior extends Behavior implements LinkerBehaviorInterface
81
81
*/
82
82
private $ dynamicFieldsOfModel = [];
83
83
84
+ /**
85
+ * Build updater instance
86
+ * @param $relationConfig
87
+ * @param $defaultUpdaterClass
88
+ * @return object
89
+ */
90
+ private function buildUpdater ($ relationConfig , $ defaultUpdaterClass )
91
+ {
92
+ if (!is_array ($ relationConfig )) {
93
+ $ relationConfig = [$ relationConfig ];
94
+ }
95
+
96
+ if (empty ($ relationConfig ['updater ' ]['class ' ])) {
97
+ if (!empty ($ relationConfig ['updater ' ])) {
98
+ $ relationConfig ['updater ' ]['class ' ] = $ defaultUpdaterClass ;
99
+ } else {
100
+ $ relationConfig ['updater ' ] = [
101
+ 'class ' => $ defaultUpdaterClass
102
+ ];
103
+ }
104
+ }
105
+
106
+ return Yii::createObject ($ relationConfig ['updater ' ]);
107
+ }
108
+
84
109
/**
85
110
* Events list
86
111
* @return array
@@ -159,11 +184,8 @@ public function saveRelations()
159
184
160
185
if (!empty ($ relation ->via ) && $ relation ->multiple ) {
161
186
// Many-to-many
162
- if (empty ($ dynamicAttributeParams ['updater ' ]['class ' ])) {
163
- $ dynamicAttributeParams ['updater ' ]['class ' ] = ManyToManyUpdater::className ();
164
- }
165
187
166
- $ updater = Yii:: createObject ($ dynamicAttributeParams[ ' updater ' ] );
188
+ $ updater = $ this -> buildUpdater ($ dynamicAttributeParams, ManyToManyUpdater:: className () );
167
189
if (!$ updater instanceof ManyToManyUpdaterInterface) {
168
190
throw new InvalidConfigException (
169
191
'Updater class must implement ' .
@@ -172,11 +194,8 @@ public function saveRelations()
172
194
}
173
195
} elseif (!empty ($ relation ->link ) && $ relation ->multiple ) {
174
196
// One-to-many on the many side
175
- if (empty ($ dynamicAttributeParams ['updater ' ]['class ' ])) {
176
- $ dynamicAttributeParams ['updater ' ]['class ' ] = OneToManyUpdater::className ();
177
- }
178
197
179
- $ updater = Yii:: createObject ($ dynamicAttributeParams[ ' updater ' ] );
198
+ $ updater = $ this -> buildUpdater ($ dynamicAttributeParams, OneToManyUpdater:: className () );
180
199
if (!$ updater instanceof OneToManyUpdaterInterface) {
181
200
throw new InvalidConfigException (
182
201
'Updater class must implement ' .
0 commit comments