MODULE_preprocess_block() get rendered region in drupal 8 So I am trying to port a Drupal 7 module to Drupal 8, and am struggling with how to translate a "NAME_preprocess_block" method. In the D7 code, it filters by the region a block is getting rendered 

if ($vars['elements']['#block']-&gt;region == "my_region") {
   // Do stuff.
}


However, the "['#block']->region" object doesn't exist in drupal 8, and I can't seem to find an alternative. Is it still possible to do this?

Thanks!
So, getting everything working here is the code I got to work.

use Drupal\block\Entity\Block;
/**
 * Implements hook_preprocess_block().
 */
function harfang_preprocess_block(&amp;$variables) {
  $block = Block::load($variables['elements']['#id']);
  $region = $block-&gt;getRegion();

 // Add classes to all bocks in footer region.
  if($region == 'footer') {
 // Do something.
  }
}


added the use statement at the top and removed the non-joiners