You are here

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

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

Retrieves the bundle info for a given entity type.

Parameters

\Drupal\views\ViewEntityInterface $view: A ViewEntityInterface object.

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::getViewBackgroundImage

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

File

src/BackgroundImageManager.php, line 643

Class

BackgroundImageManager

Namespace

Drupal\background_image

Code

public function getViewBackgroundImage(ViewEntityInterface $view, $langcode = NULL, array $context = []) {
  if ($this
    ->validView($view)) {
    $result = $this->storage
      ->loadByProperties([
      'type' => BackgroundImageInterface::TYPE_VIEW,
      'target' => "{$view->id()}:{$view->getExecutable()->current_display}",
    ]);
    if ($backgroundImage = reset($result)) {
      return $this->entityRepository
        ->getTranslationFromContext($backgroundImage, $langcode, $context);
    }
  }
  return NULL;
}