I have created a block type in the drupal 8 UI (structure/block/block-content/types ) that has two fields that are just strings. I then created 4 pieces of content using that block_type. How do I access the content created by the block type in hook_preprocessor_html programmatically?
1 Answer
This is a cutdown version of the function to access the block entities.
function _access_content_block_fields_build_arr($bidArr, $fieldRequestArr)
{
$return = array();
$blockElements = array();
$blocks = \Drupal\block_content\Entity\BlockContent::loadMultiple($bidArr);
foreach ($blocks as $block) {
foreach ($fieldRequestArr as $fieldRequest) {
$blockResult = $block->get($fieldRequest)->getValue();
$blockElements[$fieldRequest] = $blockResult[0];
}
$return[] = $blockElements;
}
return $return;
}
purencool.com/accessing-a-block-types-content-programatically is the entire function for image fields url as well