You are here

public function BackgroundImageManager::getGlobalBackgroundImage in Background Image 2.0.x

Same name and namespace in other branches
  1. 8 src/BackgroundImageManager.php \Drupal\background_image\BackgroundImageManager::getGlobalBackgroundImage()
  2. 2.x src/BackgroundImageManager.php \Drupal\background_image\BackgroundImageManager::getGlobalBackgroundImage()

Retrieves a fallback or "global" background image for the entire site.

Parameters

string $langcode: (optional) The language of the current context. Defaults to the current content language.

array $context: (optional) An associative array of arbitrary data that can be useful to determine the proper fallback sequence.

Return value

\Drupal\background_image\BackgroundImageInterface|null A background image entity, if one exists.

Overrides BackgroundImageManagerInterface::getGlobalBackgroundImage

1 call to BackgroundImageManager::getGlobalBackgroundImage()
BackgroundImageManager::getBackgroundImage in src/BackgroundImageManager.php
Retrieves a background image based on the current route.

File

src/BackgroundImageManager.php, line 590

Class

BackgroundImageManager

Namespace

Drupal\background_image

Code

public function getGlobalBackgroundImage($langcode = NULL, array $context = []) {
  $result = $this->storage
    ->loadByProperties([
    'type' => BackgroundImageInterface::TYPE_GLOBAL,
  ]);
  if ($backgroundImage = reset($result)) {
    return $this->entityRepository
      ->getTranslationFromContext($backgroundImage, $langcode, $context);
  }
  return NULL;
}