You are here

protected function EntityRenderHandler::buildPreviewImageAttributeSource in Acquia Lift Connector 8.4

Build a preview image attribute source.

Parameters

$view_modes: View modes available to check.

$preview_view_mode: View mode that represents the preview image.

$style: Image style for the preview image.

$translation: Translation to use to build the source.

Return value

string|null The source string returned or nothing.

1 call to EntityRenderHandler::buildPreviewImageAttributeSource()
EntityRenderHandler::onCreateCdf in modules/acquia_lift_publisher/src/EventSubscriber/Cdf/EntityRenderHandler.php
Actions on create CDF.

File

modules/acquia_lift_publisher/src/EventSubscriber/Cdf/EntityRenderHandler.php, line 261

Class

EntityRenderHandler
Class EntityRenderHandler.

Namespace

Drupal\acquia_lift_publisher\EventSubscriber\Cdf

Code

protected function buildPreviewImageAttributeSource($view_modes, $preview_view_mode, $style, $translation) {

  // Does the view mode exist?
  if (empty($view_modes[$preview_view_mode])) {
    return NULL;
  }

  // Can we load this view mode?
  $preview_image = $translation->{$view_modes[$preview_view_mode]}
    ->first();
  if (empty($preview_image)) {
    return NULL;
  }

  // Can we get a source url for the image style using the view mode?
  $src = ImageStyle::load($style)
    ->buildUrl($preview_image->entity
    ->getFileUri());
  if (empty($src)) {
    return NULL;
  }
  return $src;
}