Skip to main content
deleted 3 characters in body
Source Link
user94449
user94449

In order to add a node to any group in Drupal 8, 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 believeBut believe I can remove a single node from a group with a simple line of code.

How can I achieve it?

In order to add a node to any group in Drupal 8, 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.

How can I achieve it?

In order to add a node to any group in Drupal 8, 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();

But believe I can remove a single node from a group with a simple line of code.

How can I achieve it?

added 2 characters in body
Source Link
user94449
user94449

In order to add a node to aany group in Drupal 8, 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.

How can I achieve it?

In order to add a node to a group in Drupal 8, 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.

How can I achieve it?

In order to add a node to any group in Drupal 8, 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.

How can I achieve it?

improved grammar
Source Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

Remove node or contents Programmatically remove content from a group programmatically

In order to add a contentnode to a group in Drupal 8, I use the below line offollowing code:.

$group->addContent($node, 'group_node:article');

Now, for removing a Contentcontent from a group, I have tried the below code:

$group->removeContent($node, 'group_node:article');

or

$group->removeContent($node);

but with no$group->removeContent($node, 'group_node:article'); and $group->removeContent($node); without success along with. All I obtained is the belowfollowing error: message.

Error: Call to undefined method Drupal\group\Entity\Group::removeContent() in Drupal\my_valetop_extras\Plugin\WebformHandler\CustomWebformHandler->submitForm() (line 211...

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 a content from a group using the belowthis code:.

$type = 'group_node:' . $node->getType();
$current_node = $group->getContent($type, ['entity_id' => $node_id]);
$content = array_values($current_node)[0];
$content->delete();

but I still believe I can remove a single contentnode from a group with onea simple line of code !.

any help please How can I achieve it?

Please note that this question is not a duplicate of Programmaticaly remove a member from a group because this question is about removing a Node and not Member from a group.

Remove node or contents from group programmatically

In order to add a content to a group in Drupal 8, I use the below line of code:

$group->addContent($node, 'group_node:article');

Now, for removing a Content from a group, I have tried the below code:

$group->removeContent($node, 'group_node:article');

or

$group->removeContent($node);

but with no success along with the below error:

Error: Call to undefined method Drupal\group\Entity\Group::removeContent() in Drupal\my_valetop_extras\Plugin\WebformHandler\CustomWebformHandler->submitForm() (line 211...

Finally, I have managed to remove a content from a group using the below code:

$type = 'group_node:' . $node->getType();
$current_node = $group->getContent($type, ['entity_id' => $node_id]);
$content = array_values($current_node)[0];
$content->delete();

but I still believe I can remove a single content from a group with one simple line of code !

any help please ?

Please note that this question is not a duplicate of Programmaticaly remove a member from a group because this question is about removing a Node and not Member from a group.

Programmatically remove content from a group

In order to add a node to a group in Drupal 8, 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.

How can I achieve it?

added 205 characters in body
Source Link
user94449
user94449
Loading
Source Link
user94449
user94449
Loading