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()->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?
hook_node_presave
you'll have access to both the pieces of information you need, that's where I'd do it