@@ -148,6 +148,9 @@ public function prepareInputForAdd($input) {
148
148
}
149
149
150
150
public function prepareInputForUpdate ($ input ) {
151
+ // Disallow changing the linked entity
152
+ unset($ input ['entities_id ' ]);
153
+
151
154
$ input ['header ' ] = $ input ['header ' ] ?? '' ;
152
155
153
156
$ config = Toolbox::getHtmLawedSafeConfig ();
@@ -156,22 +159,31 @@ public function prepareInputForUpdate($input) {
156
159
return $ input ;
157
160
}
158
161
162
+ protected static function createDefaultsForEntity ($ entityId ): self {
163
+ $ entityConfig = new self ();
164
+ if ($ entityConfig ->getFromDbByCrit (['entities_id ' => $ entityId ])) {
165
+ return $ entityConfig ;
166
+ }
167
+
168
+ $ entityConfig ->add ([
169
+ 'entities_id ' => $ entityId ,
170
+ 'replace_helpdesk ' => self ::CONFIG_PARENT ,
171
+ 'is_kb_separated ' => self ::CONFIG_PARENT ,
172
+ 'is_search_visible ' => self ::CONFIG_PARENT ,
173
+ 'is_header_visible ' => self ::CONFIG_PARENT ,
174
+ 'sort_order ' => self ::CONFIG_PARENT ,
175
+ ]);
176
+
177
+ return $ entityConfig ;
178
+ }
179
+
159
180
public function showFormForEntity (Entity $ entity ) {
160
- $ ID = $ entity ->getField ( ' id ' );
181
+ $ ID = $ entity ->getID ( );
161
182
if (!$ entity ->can ($ ID , READ )) {
162
183
return false ;
163
184
}
164
185
165
- if (!$ this ->getFromDbByCrit (['entities_id ' => $ ID ])) {
166
- $ this ->add ([
167
- 'entities_id ' => $ ID ,
168
- 'replace_helpdesk ' => self ::CONFIG_PARENT ,
169
- 'is_kb_separated ' => self ::CONFIG_PARENT ,
170
- 'is_search_visible ' => self ::CONFIG_PARENT ,
171
- 'is_header_visible ' => self ::CONFIG_PARENT ,
172
- 'sort_order ' => self ::CONFIG_PARENT ,
173
- ]);
174
- }
186
+ $ this ->getFromDB (self ::createDefaultsForEntity ($ ID )->getID ());
175
187
176
188
$ canedit = Entity::canUpdate () && $ entity ->canUpdateItem ();
177
189
echo "<div class='spaced'> " ;
@@ -389,6 +401,7 @@ static function getUsedConfig($fieldref, $entities_id, $fieldval = '', $default_
389
401
// Search in entity data of the current entity
390
402
if ($ entity ->getFromDB ($ entities_id )) {
391
403
// Value is defined : use it
404
+ self ::createDefaultsForEntity ($ entities_id );
392
405
if ($ entityConfig ->getFromDBByCrit (['entities_id ' => $ entities_id ])) {
393
406
if (is_numeric ($ default_value )
394
407
&& ($ entityConfig ->fields [$ fieldref ] != self ::CONFIG_PARENT )) {
0 commit comments