Get unsaved node from route parameter What I want: In hook_media_presave I want to set a field value according to the same field on the referring node.

By the referring node, I mean the node where the media entity is created through an entity reference field.

I don't know if this is possible at all, but if it is, then how?

My current approach is to get the node from the route like this inside the presave hook:

$node = \Drupal::routeMatch()-&gt;getParameter('node');


My problem: The node I get from the routeMatch doesn't contain the new changes. Is there a way to somehow get them using the routeMatch, or is there another way to get the node.

I thought maybe the media entity had some kind of getReferringEntity() method, but no.

Is this the correct approach, or am I wrong?
With the help from @Clive I found a solution:

/**
 * Implements hook_node_update().
 */
function MY_MODULE_node_update(\Drupal\node\NodeInterface $node) {
  foreach ($node-&gt;getFieldDefinitions() as $definition) {
    if (!in_array($definition-&gt;getType(), ['entity_reference', 'entity_reference_revisions'])) {
      continue;
    }
    if (!$definition-&gt;getSetting('target_type')) {
      continue;
    }
    if ($definition-&gt;getSetting('target_type') == 'media') {
      $media = $node-&gt;{$definition-&gt;getName()}-&gt;entity;
      if ($media) {
        $media-&gt;groups-&gt;target_id = $node-&gt;groups-&gt;target_id;
        $media-&gt;save();
      }
    }
    if ($definition-&gt;getSetting('target_type') == 'paragraph') {
      $paragraph = $node-&gt;{$definition-&gt;getName()}-&gt;entity;
      if ($paragraph) {
        MY_MODULE_update_media_items($paragraph, $node-&gt;groups);
      }
    }
  }
}

/**
 * Set groups on all media items referenced in a paragraph.
 *
 * @param $paragraph
 *   The paragraph.
 * @param $groups
 *   The groups to set.
 */
function MY_MODULE_update_media_items($paragraph, $groups) {
  foreach ($paragraph-&gt;getFieldDefinitions() as $definition) {
    if (!in_array($definition-&gt;getType(), ['entity_reference', 'entity_reference_revisions'])) {
      continue;
    }
    if (!$definition-&gt;getSetting('target_type')) {
      continue;
    }
    if ($definition-&gt;getSetting('target_type') == 'media') {
      $media = $paragraph-&gt;{$definition-&gt;getName()}-&gt;entity;
      if ($media) {
        $media-&gt;groups-&gt;target_id = $groups-&gt;target_id;
        $media-&gt;save();
      }
    }
    if ($definition-&gt;getSetting('target_type') == 'paragraph') {
      $paragraph = $paragraph-&gt;{$definition-&gt;getName()}-&gt;entity;
      if ($paragraph) {
        MY_MODULE_update_media_items($paragraph, $groups);
      }
    }
  }
}