You are here

public function HttpStatusCodeDisplayVariant::build in Page Manager 8

Same name and namespace in other branches
  1. 8.4 src/Plugin/DisplayVariant/HttpStatusCodeDisplayVariant.php \Drupal\page_manager\Plugin\DisplayVariant\HttpStatusCodeDisplayVariant::build()

Builds and returns the renderable array for the display variant.

The variant can contain cacheability metadata for the configuration that was passed in setConfiguration(). In the build() method, this should be added to the render array that is returned.

Return value

array A render array for the display variant.

Overrides VariantInterface::build

File

src/Plugin/DisplayVariant/HttpStatusCodeDisplayVariant.php, line 77
Contains \Drupal\page_manager\Plugin\DisplayVariant\HttpStatusCodeDisplayVariant.

Class

HttpStatusCodeDisplayVariant
Provides a variant that returns a response with an HTTP status code.

Namespace

Drupal\page_manager\Plugin\DisplayVariant

Code

public function build() {
  $status_code = $this->configuration['status_code'];
  if ($status_code == 200) {
    return [];
  }
  else {
    throw new HttpException($status_code);
  }
}