0

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');
$urifacebook=$pathmodule.'/src/img/facebook.png';

//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 ?

New contributor
Antoine Moulin is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
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.

New contributor
Antoine Moulin is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Your Answer

Antoine Moulin is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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