I am having trouble adding a class to an image using a preprocessor function in Drupal 9. Specifically, I only want certain images to have that class added. The image is being added using paragraphs.
I've tried a few variations of the following and cannot seem to get class added. I've also tried using ['#item']
but it causes an error.
function confluence_preprocess_field__paragraph__field_card_image(&$variables) {
foreach($variables['items'] as $key => $item){
$variables['items'][ $key ]['content']['item']['class'] = 'card-img-top';
}
}