private function PageContext::setThumbnailUrl in Acquia Lift Connector 8
Set thumbnail URL.
Parameters
\Drupal\Core\Entity\EntityInterface $node: Node.
1 call to PageContext::setThumbnailUrl()
- PageContext::setByNode in src/
Service/ Context/ PageContext.php - Set page context by node.
File
- src/
Service/ Context/ PageContext.php, line 111 - Contains \Drupal\acquia_lift\Service\Context\PageContext.
Class
Namespace
Drupal\acquia_lift\Service\ContextCode
private function setThumbnailUrl(EntityInterface $node) {
$node_type = $node
->getType();
// Don't set, if no thumbnail has been configured.
if (!isset($this->thumbnailConfig[$node_type])) {
return;
}
$node_type_thumbnail_config = $this->thumbnailConfig[$node_type];
$thumbnail_config_array = explode('->', $node_type_thumbnail_config['field']);
$entity = $node;
foreach ($thumbnail_config_array as $field_key) {
// Don't set, if node has no such field or field has no such entity.
if (empty($entity->{$field_key}->entity) || method_exists($entity->{$field_key}, 'isEmpty') && $entity->{$field_key}
->isEmpty()) {
return;
}
$entity = $entity->{$field_key}->entity;
}
if ($entity
->bundle() !== 'file') {
return;
}
$fileUri = $entity
->getFileUri();
// Process Image style.
$image_style = ImageStyle::load($node_type_thumbnail_config['style']);
// Return empty if no such image style.
if (empty($image_style)) {
return;
}
// Generate image URL.
$thumbnail_uri = $image_style
->buildUrl($fileUri);
$this->pageContext['thumbnail_url'] = file_create_url($thumbnail_uri);
}