I'am learning Drupal 8, and I would like create a custom module who create a block to add share button. The link of this button should be an image who stocked in my custom module. I would like use an image style on my picture.

Last but not least, i want use a render array.

In my build() method of my customblock.php i have whrite :

//create url link
$url = Url::fromUri('https://www.facebook.com/sharer/sharer.php?u='.$base_url.Url::fromRoute('<current>')->toString());

//create uri image
$pathmodule=drupal_get_path('module', 'share_configurable');

//render array of link
if ($this->configuration['network']['facebook']=='facebook'){
  $build['link_facebook'] = [
    '#title' => [
      '#theme' => 'image_style',
      '#style_name' => 'thumbnail',
      '#uri' => $urifacebook,
    '#type' => 'link',
    '#url' => $url

The link is create, but the image is not render... Can you help me please ?


1 Answer 1


Thank to Hudri : Image styles only work with managed files (uploaded, with entry in DB), not with static assets. Since this is a static asset anyway, just provide the correct size in your module.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.