The 'attachments' is not a real DB field here. It comes from the form's
filepicker and holds the id of the attachments filearea. The function
forum_add_attachment() expects it as a property of the first argument.
There were two possible approaches here. Either to pass the raw $newpost
to forum_add_attachment(), or add the attachments into the list
modifiable fields. The second approach is safer.
'timestart',
'timeend',
'pinned',
+ 'attachments',
];
foreach ($modifiablefields as $field) {
if (isset($newpost->{$field})) {