How to access field values from a custom block How do you give a custom block (in a custom module) access to field values produced by the context of page?

eg: If the page has a field, say 'field_my_custom_id' and I want to use it for some purpose in the Build function of a custom block, how to access it from within my module?
At the point when you build your block you don't know what other code will put in the page.

As alternative you can use the routing system, because the route is resolved in the bootstrap process (in D8 the symfony framework) before any custom code is run:

if ($node = \Drupal::routeMatch()-&gt;getParameter('node')) {
  $field_my_custom_id = $node-&gt;field_my_custom_id-&gt;value;
}


Of course you don't know if other code will put this field on the page, but you know that the url of the page will produce the specific node as main content.