When a group entity is saved, the group module uses $this->operation == 'edit'
to determine if the group is being created (net-new) or being updated, for the purpose of displaying the message. https://git.drupalcode.org/project/group/-/blob/3.0.x/src/Entity/Form/GroupForm.php?ref_type=heads#L93
This is different from the core Node module that uses $this->entity->isNew()
to determine if the node is being created (net-new) or being updated. https://git.drupalcode.org/project/drupal/-/blob/10.2.x/core/modules/node/src/NodeForm.php?ref_type=heads#L275
When using form displays to create different displays of the group entity form, the operation comes in as the form mode machine name, and not necessarily named operations like edit
. This results in the Group module outputting the message "@type %title has been created."
, instead of "@type %title has been updated."
, when a group is updated.
/admin/structure/display-modes/form
; group
and simple_edit
for this example.function mymodule_entity_type_build(array &$entity_types) {
$entity_types['group']->setFormClass('group', 'Drupal\group\Entity\Form\GroupForm');
$entity_types['group']->setFormClass('simple_edit', 'Drupal\group\Entity\Form\GroupForm');
}
$form_object = $this->entityTypeManager
->getFormObject('group', 'group')
->setEntity($group);
//or
$form_object = $this->entityTypeManager
->getFormObject('group', 'simple_edit')
->setEntity($group);
Issue:
When editing an existing group, and saving, if the form mode uses a created form mode to display the form, the confirmation message always says "...group has been created" and not "...group has been edited".
For the purpose of displaying the message, use $group->isNew()
to determine if the group is being created (net-new) or being updated.
Code update
None
None
None
Active
3.2
Code