You are here

public function BackgroundImageViewBuilder::build in Background Image 8

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

Builds an entity's view; augments entity defaults.

This function is assigned as a #pre_render callback in ::view().

It transforms the renderable array for a single entity to the same structure as if we were rendering multiple entities, and then calls the default ::buildMultiple() #pre_render callback.

Parameters

array $build: A renderable array containing build information and context for an entity view.

Return value

array The updated renderable array.

Overrides EntityViewBuilder::build

See also

\Drupal\Core\Render\RendererInterface::render()

File

src/BackgroundImageViewBuilder.php, line 15

Class

BackgroundImageViewBuilder

Namespace

Drupal\background_image

Code

public function build(array $build) {

  /** @type \Drupal\background_image\BackgroundImageInterface $background_image */
  $background_image = $build['#background_image'];
  $manager = BackgroundImageManager::service();
  switch ($build['#view_mode']) {
    case 'image':
      $build['image'] = $this
        ->buildImage($background_image, $manager);
      break;
    case 'text':
      $build['image'] = $this
        ->buildText($background_image, $manager);
      break;
    default:
    case 'full':
      $build['image'] = $this
        ->buildImage($background_image, $manager);
      $build['text'] = $this
        ->buildText($background_image, $manager);
      break;
  }
  return $build;
}