New answers tagged

-2 votes

How can I programmatically save node components?

$entity = \Drupal::entityTypeManager()->getStorage('cohesion_layout')->load($node->get('field_layout_canvas')->getValue()[0]['target_id']); $layoutCanvas = $entity->...
Pratik Kadambari's user avatar
0 votes

How to programmatically add content to a group in the Group Module?

Once installed the type of relationship in the group with the code feels should be sufficient for Drupal 8, 9, 10. $node = Node::create([ 'type' => 'node_type', 'title' => 'My title', 'uid'...
Abel Salas Lopez's user avatar
1 vote

How to restrict access to some nodes based on roles or users?

This is a few years old but I thought I would throw in an answer on how to do this with a very light weight custom module. This answer would be applicable to Drupal 8, 9, and 10. I am using Drupal 8 ...
serverjohn's user avatar
0 votes

How to programmatically set a node field as empty?

For Drupal 8 and above: $entity->set('body', []); $entity->save();
israelshmueli's user avatar

Top 50 recent answers are included