- last update
over 1 year ago 9,627 pass - πΊπΈUnited States i.mcbride
Here is a version which will apply against 2.1.x. I've changed the name from removeContent() to removeRelationship() to conform to function names in the 2.1.x branch.
In order to add a node to a group, I use the following code.
$group->addContent($node, 'group_node:article');
Now, for removing content from a group, I have tried
$group->removeContent($node, 'group_node:article');
and
$group->removeContent($node);
without success. All I obtained is the following error message.
Error: Call to undefined method Drupal\group\Entity\Group::removeContent() in Drupal\my_valetop_extras\Plugin\WebformHandler\CustomWebformHandler->submitForm()
Finally, I have managed to remove content from a group using this code.
$type = 'group_node:' . $node->getType();
$current_node = $group->getContent($type, ['entity_id' => $node_id]);
$content = array_values($current_node)[0];
$content->delete();
I still believe I can remove a single node from a group with a simple line of code.
Can you please add such function to the group module ? Same idea as removeMember()
which is the inverse of addMember()
Thank you,
Needs review
1.0
Code
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.
Here is a version which will apply against 2.1.x. I've changed the name from removeContent() to removeRelationship() to conform to function names in the 2.1.x branch.