I have 3 content types A, B, C. B and C have entity reference fields that reference to A and B and with different machine names. I want to get the parent node ID from referenced node.
A is referenced to B B is referenced to C
Now if I am on A then I want to get B node id and if I am on B then I want to get C node id.
How can I achieve this programatically.