You are here

protected function BackgroundImageViewBuilder::getEntity in Background Image 8

Same name and namespace in other branches
  1. 2.x src/BackgroundImageViewBuilder.php \Drupal\background_image\BackgroundImageViewBuilder::getEntity()
  2. 2.0.x src/BackgroundImageViewBuilder.php \Drupal\background_image\BackgroundImageViewBuilder::getEntity()

Determines the property entity to associate with this background image.

@todo This should really be moved to the BackgroundImage entity class.

Parameters

\Drupal\background_image\BackgroundImageInterface $background_image: The background image being processed.

\Drupal\background_image\BackgroundImageManagerInterface $manager: The Background Image Manager service.

Return value

\Drupal\Core\Entity\EntityInterface|null

2 calls to BackgroundImageViewBuilder::getEntity()
BackgroundImageViewBuilder::buildImage in src/BackgroundImageViewBuilder.php
Builds the image render array.
BackgroundImageViewBuilder::buildText in src/BackgroundImageViewBuilder.php
Builds the text render array.

File

src/BackgroundImageViewBuilder.php, line 202

Class

BackgroundImageViewBuilder

Namespace

Drupal\background_image

Code

protected function getEntity(BackgroundImageInterface $background_image, BackgroundImageManagerInterface $manager) {
  $type = $background_image
    ->getType();

  // Determine the proper "entity" to use.
  if ($entity = $background_image
    ->getTargetEntity()) {

    // Intentionally left empty, this is a specific associated entity.
  }
  else {
    if (($view = $background_image
      ->getTargetView()) && $view
      ->status()) {
      $entity = $view;
    }
    else {
      if ($type === BackgroundImageInterface::TYPE_ENTITY_BUNDLE && (list($entity_type, $bundle) = $background_image
        ->getTarget(TRUE)) && ($entity = $manager
        ->getEntityFromCurrentRoute($entity_type, $bundle))) {

        // Intentionally left empty. Entity is assigned in the if block to ensure
        // that if it doesn't find one, to move on to the next if statement.
      }
      else {
        if ($type === BackgroundImageInterface::TYPE_GLOBAL || $type === BackgroundImageInterface::TYPE_PATH || $type === BackgroundImageInterface::TYPE_ROUTE) {
          $entity = $manager
            ->getEntityFromCurrentRoute();
        }
      }
    }
  }
  return $entity;
}