In OgComplex::massageFormValues() the values of the "other groups" field are appended to the values of the "groups audience" field. This is not implemented correctly. It is currently assumed that the widget is always located in the same location as in the entity edit form, but this is obviously not always true:
public function massageFormValues(array $values, array $form, FormStateInterface $form_state) {
// It is not at all certain that the other_groups field is located
// at $form['og_group_ref*']['other_groups'] (*or similar).
foreach ($form[$this->fieldDefinition->getName()]['other_groups'] as $key => $value) {
// ...
}
// ...
}
The documentation of the method also indicates that the $form parameter does not necessarily represent the entire form, it also might be a form element that is part of a larger form. We need to rethink the way we are dealing with this situation.
One place where this is currently causing errors is in the field edit form. The widget is rendered here so you can provide default values.
For example these steps will trigger this false behaviour:
Turn the 'article' content type into a group content type.
Go to the field edit form of the groups audience field (admin/structure/types/manage/article/fields/node.article.og_group_ref).
Submit the form.
The following error occurs and the default value of the "other groups" field is not saved:
In
OgComplex::massageFormValues()
the values of the "other groups" field are appended to the values of the "groups audience" field. This is not implemented correctly. It is currently assumed that the widget is always located in the same location as in the entity edit form, but this is obviously not always true:The documentation of the method also indicates that the
$form
parameter does not necessarily represent the entire form, it also might be a form element that is part of a larger form. We need to rethink the way we are dealing with this situation.One place where this is currently causing errors is in the field edit form. The widget is rendered here so you can provide default values.
For example these steps will trigger this false behaviour:
Let's wait until the big refactoring in #161 is done before tackling this.