SimplePageVariant.php in Drupal 9
File
core/lib/Drupal/Core/Render/Plugin/DisplayVariant/SimplePageVariant.php
View source
<?php
namespace Drupal\Core\Render\Plugin\DisplayVariant;
use Drupal\Core\Display\PageVariantInterface;
use Drupal\Core\Display\VariantBase;
class SimplePageVariant extends VariantBase implements PageVariantInterface {
protected $mainContent;
protected $title = '';
public function setMainContent(array $main_content) {
$this->mainContent = $main_content;
return $this;
}
public function setTitle($title) {
$this->title = $title;
return $this;
}
public function build() {
$build = [
'content' => [
'messages' => [
'#type' => 'status_messages',
'#weight' => -1000,
'#include_fallback' => TRUE,
],
'page_title' => [
'#type' => 'page_title',
'#title' => $this->title,
'#weight' => -900,
],
'main_content' => [
'#weight' => -800,
] + $this->mainContent,
],
];
return $build;
}
}