public function BackgroundImageManager::getEntityBackgroundImage in Background Image 8
Same name and namespace in other branches
- 2.x src/BackgroundImageManager.php \Drupal\background_image\BackgroundImageManager::getEntityBackgroundImage()
- 2.0.x src/BackgroundImageManager.php \Drupal\background_image\BackgroundImageManager::getEntityBackgroundImage()
Retrieves a background image that matches a specific entity.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: The entity to use as the target.
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::getEntityBackgroundImage
2 calls to BackgroundImageManager::getEntityBackgroundImage()
- BackgroundImageManager::alterEntityForm in src/
BackgroundImageManager.php - Perform alterations before a form is rendered.
- BackgroundImageManager::getBackgroundImage in src/
BackgroundImageManager.php - Retrieves a background image based on the current route.
File
- src/
BackgroundImageManager.php, line 420
Class
Namespace
Drupal\background_imageCode
public function getEntityBackgroundImage(EntityInterface $entity, $langcode = NULL, array $context = []) {
if ($this
->validEntity($entity)) {
$entity_type = $entity
->getEntityType();
$result = $this->storage
->loadByProperties([
'type' => BackgroundImageInterface::TYPE_ENTITY,
'target' => $entity_type
->id() . ':' . $entity
->uuid(),
]);
if ($backgroundImage = reset($result)) {
return $this->entityRepository
->getTranslationFromContext($backgroundImage, $langcode, $context);
}
}
return NULL;
}