You are here

public function BackgroundImage::getTargetView in Background Image 2.0.x

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

Retrieves the target entity view, if the type is supported and exists.

Parameters

int $type: The type. Defaults to the currently set type.

string $target: A target identifier split by a colon (:) where the view identifier is on the left and the page display identifier to load is on the right. Defaults to the currently set target.

Return value

\Drupal\views\ViewEntityInterface|null The target View object or NULL if not a valid target.

Overrides BackgroundImageInterface::getTargetView

1 call to BackgroundImage::getTargetView()
BackgroundImage::label in src/Entity/BackgroundImage.php
Gets the label of the entity.

File

src/Entity/BackgroundImage.php, line 539

Class

BackgroundImage
Defines the Background Image entity.

Namespace

Drupal\background_image\Entity

Code

public function getTargetView($type = NULL, $target = NULL) {
  if (!isset($type)) {
    $type = $this
      ->getType();
  }
  if (!isset($target)) {
    $target = $this
      ->getTarget();
  }

  /** @var \Drupal\views\ViewEntityInterface $view */
  $view = NULL;
  if ($type === self::TYPE_VIEW) {
    [
      $view_id,
      $display_id,
    ] = explode(':', $target);
    if (isset($view_id) && isset($display_id) && ($view = $this
      ->entityTypeManager()
      ->getStorage('view')
      ->load($view_id))) {
      $view_executable = $view
        ->getExecutable();
      $view_executable
        ->setDisplay($display_id);
      if (!$this
        ->getBackgroundImageManager()
        ->validView($view)) {
        $view = NULL;
      }
    }
  }
  return $view;
}