Skip to content

Instantly share code, notes, and snippets.

@thebrainroom
Last active December 20, 2016 11:34
Show Gist options
  • Save thebrainroom/4547d4f99e1203cd8e9491498a453cae to your computer and use it in GitHub Desktop.
Save thebrainroom/4547d4f99e1203cd8e9491498a453cae to your computer and use it in GitHub Desktop.
Get image style programmatically for Drupal 8
<?php
use Drupal\image\Entity\ImageStyle;
function blissgo_preprocess_node(&$variables) {
$node = $variables['node'];
if(!empty($node->field_image[0])) {
$path = $node->field_image->entity->getFileUri();
$url = ImageStyle::load('teaser_image')->buildUrl($path);
$variables['teaser_image_url'] = $url;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment