How can I access block field values in mytheme_preprocess_block? My fundamental question is this: in Drupal 8 how can I access block field values in mytheme_preprocess_block.

I am trying to achieve something like https://www.drupal.org/project/block_class_styles in Drupal 8.

So far I have created the block field, and extracted the raw field value in twig (and then add classes or conditional statements) by doing something like:

{{ content.field_layout_style[0]['#markup']|escape }}


This looks really bad, I would rather access this field value in mytheme_preprocess_block, and then pass it to twig, and/or access it in  mytheme_theme_suggestions_block_alter and make separate template suggestions based on it.

Help very much appreciated.
Here is a code snippet that we use to create block template suggestions based on the block content type (bundle), doing something similar based on a field should be fairly easy (...->yourfield->value):

/**
 * Implements hook_theme_suggestions_HOOK_alter() for block templates.
 */
function ourtheme_theme_suggestions_block_alter(array &amp;$suggestions, array $variables) {
  if (isset($variables['elements']['content']['#block_content'])) {
    $suggestions[] = 'block__' . $variables['elements']['content']['#block_content']-&gt;bundle();
    $suggestions[] = 'block__' . $variables['elements']['content']['#block_content']-&gt;bundle() . '__' . $variables['elements']['content']['#view_mode'];
  }
}