Add to Custom Entity Content on Node add/update I am new to Drupal. Now, learning drupal 8.

I have added a module from command drupal generate:module named 'my_module`

I have added an entity for my_module:

drupal generate:entity:content
//bundle "NO"


What I want

I would like to add/insert in to this entity on every Node add/update.

I have got this code into my my_module.module

function my_module_form_node_form_alter(&amp;$form, \Drupal\Core\Form\FormStateInterface $form_state)
{
    foreach (array_keys($form['actions']) as $action) {
      if ($action != 'preview' &amp;&amp; isset($form['actions'][$action]['#type']) &amp;&amp; $form['actions'][$action]['#type'] === 'submit') {
        $form['actions'][$action]['#submit'][] = 'my_module_node_form_submit';
      }
    }
}

function my_module_node_form_submit($form, \Drupal\Core\Form\FormStateInterface $form_state) {
   $node = $form_state-&gt;getFormObject()-&gt;getEntity();

   $url = $node-&gt;field_website-&gt;uri; //my node field
   $name = $node-&gt;field_com-&gt;value; //my node field

   //HOW TO ADD $url, $name IN TO above custom ENTITY
}


My entity table:

1: my_module

id
uuid
langcode


2: my_module_field_data

id PrimaryIndex
langcode PrimaryIndex
name
url
status
created
changed
default_langcode Index


Please help.
You can do like this

Suppose your entity name is my_entity.

&lt;?php
use Drupal\my_module\Entity\my_entity;

function my_module_form_node_form_alter(&amp;$form, \Drupal\Core\Form\FormStateInterface $form_state)
{
    foreach (array_keys($form['actions']) as $action) {
        if ($action != 'preview' &amp;&amp; isset($form['actions'][$action]['#type']) &amp;&amp; $form['actions'][$action]['#type'] === 'submit') {
            $form['actions'][$action]['#submit'][] = 'my_module_node_form_submit';
        }
    }
}

function my_module_node_form_submit($form, \Drupal\Core\Form\FormStateInterface $form_state) {
    $node = $form_state-&gt;getFormObject()-&gt;getEntity();

    $url = $node-&gt;field_website-&gt;uri;
    $name = $node-&gt;field_com-&gt;value;

    // Now to check    
    //Generate my_entity entity.
    $entity = my_entity::create(
               [
                 'label' =&gt; 'token',
                 'id' =&gt; $node-&gt;id(),
                 'status' =&gt; true,
                 'name'=&gt; $url,
                  "url" =&gt; $name,
                  "created" =&gt; time()
               ]
         );
    $entity-&gt;save();
}


To update enity:

$entity = my_entity::load('content entity id');
$entity-&gt;set("name", 'name value');
$entity-&gt;set("url", 'url value');
$entity-&gt;save();