Updating node title inside Rules Action I am creating a Rules Action that will update the node title after it is created.

Here is my code, but when I try to create new content using Postman, it keeps loading. I dont get response in Drupal logs.

...
class ContentTitle extends RulesActionBase {

  protected function doExecute(EntityInterface $entity) {

    $entity_id = $entity-&gt;id(); // Getting dynamic entity ID
    $controller = \Drupal::entityManager()-&gt;getStorage('node');
    $node = $controller-&gt;load($entity_id);

    $title = $entity-&gt;label();
    $item = $node-&gt;get('field_xyz')-&gt;value;
    $new_title = "Title is " . $title . $item;

    \Drupal::logger('custom_rules')-&gt;notice('new_title: ' . $new_title);

    $data = array(
      'type' =&gt; 'custom_content',
      'title' =&gt; [
        'value' =&gt; $new_title,
      ]
    );
    $node = Drupal::entityManager()
      -&gt;getStorage('node')
      -&gt;create($data);
    $node-&gt;save();
  }
}


Im getting the expected output in the logger.

I dont think I am setting the title in $data properly. Any suggestion is greatly appreciated. Thanks!
You can set a node's title with the &quot;Set a data value&quot; action - you don't need to write your own action. I'm going to assume that you're putting this into your own action because there are other things you want to do that you haven't mentioned or because you are learning how to write an action - if this is ONLY about setting the title then I don't see the point of a custom action.
Problems with the approach and the partial solution given in the initial post:

You don't need to get the entity ID then load the entity from
storage, because Rules is already passing you the loaded entity.

You're using entity instead of node, which wrong - Nodes have
titles, Entities in general DON'T.

You're hardwiring in a title taken from a specific field 'field_xyz'.
Instead, you should pass in a string variable which holds the title.
That way the Rule configuration can get the value out of 'field_xyz'
or out of 'field_nlm' or from a thousand other places - writing the
action with a string parameter will make it far more useful.

The EntityManager has been deprecated since Drupal 8.0 and should not be used. You should be using EntityTypeManager instead. But as I said in #1, this isn't even needed.

You don't have to save the node, Rules will handle the saving
automatically.


This really only requires one line of code (plus some boilerplate code, like all plugins...). Here's a complete solution that takes two context variables:

The node to change.
The title to use.


namespace Drupal\my_module\Plugin\RulesAction;

use Drupal\node\NodeInterface;
use Drupal\rules\Core\RulesActionBase;

/**
 * Sets the title of a content item.
 *
 * @RulesAction(
 *   id = &quot;rules_node_set_title&quot;,
 *   label = @Translation(&quot;Sets the title of the selected content item&quot;),
 *   category = @Translation(&quot;Content&quot;),
 *   context_definitions = {
 *     &quot;node&quot; = @ContextDefinition(&quot;entity:node&quot;,
 *       label = @Translation(&quot;Node&quot;),
 *       description = @Translation(&quot;Specifies the content item to change.&quot;),
 *       assignment_restriction = &quot;selector&quot;
 *     ),
 *     &quot;title&quot; = @ContextDefinition(&quot;string&quot;,
 *       label = @Translation(&quot;Title&quot;),
 *       description = @Translation(&quot;The new title.&quot;)
 *     ),
 *   }
 * )
 */
class NodeSetTitle extends RulesActionBase {

  /**
   * Executes the action with the given context.
   *
   * @param \Drupal\node\NodeInterface $node
   *   The node to modify.
   * @param string $title
   *   The new title.
   */
  protected function doExecute(NodeInterface $node, $title) {
    $node-&gt;setTitle($title);
  }

  /**
   * {@inheritdoc}
   */
  public function autoSaveContext() {
    // The node should be auto-saved after the execution.
    return ['node'];
  }

}