You are here

protected function ShareMessage::getImageUrl in Share Message 8

Gets the image url of the ShareMessage.

Parameters

array $context: The context for the token replacements.

\Drupal\file\FileInterface|null $fallback_image: By-reference argument that holds the fallback image reference if that was used.

Return value

bool|string The found URL or FALSE.

2 calls to ShareMessage::getImageUrl()
ShareMessage::buildOGTags in src/Entity/ShareMessage.php
Returns Open Graph meta tags for <head>.
ShareMessage::buildTwitterCardTags in src/Entity/ShareMessage.php
Adds meta tags in order to share images on Twitter.

File

src/Entity/ShareMessage.php, line 535

Class

ShareMessage
Entity class for the Share Message entity.

Namespace

Drupal\sharemessage\Entity

Code

protected function getImageUrl($context, &$fallback_image = NULL) {

  // Get image url either from dedicated file field or by resolving token.
  $image_url = $this
    ->getTokenizedField($this->image_url, $context);

  // If the returned image URl is empty, try to use the fallback image if
  // one is defined.
  if (!$image_url && !empty($this->fallback_image)) {
    $entity_repository = \Drupal::getContainer()
      ->get('entity.repository');

    /** @var \Drupal\file\FileInterface $image */
    $fallback_image = $entity_repository
      ->loadEntityByUuid('file', $this->fallback_image);
    if ($fallback_image) {
      $image_url = file_create_url($fallback_image
        ->getFileUri());
    }
  }
  return $image_url;
}