Version 1
[yaffs-website] / web / core / lib / Drupal / Core / Render / Plugin / DisplayVariant / SimplePageVariant.php
1 <?php
2
3 namespace Drupal\Core\Render\Plugin\DisplayVariant;
4
5 use Drupal\Core\Display\PageVariantInterface;
6 use Drupal\Core\Display\VariantBase;
7
8 /**
9  * Provides a page display variant that simply renders the main content.
10  *
11  * @PageDisplayVariant(
12  *   id = "simple_page",
13  *   admin_label = @Translation("Simple page")
14  * )
15  */
16 class SimplePageVariant extends VariantBase implements PageVariantInterface {
17
18   /**
19    * The render array representing the main content.
20    *
21    * @var array
22    */
23   protected $mainContent;
24
25   /**
26    * The page title: a string (plain title) or a render array (formatted title).
27    *
28    * @var string|array
29    */
30   protected $title = '';
31
32   /**
33    * {@inheritdoc}
34    */
35   public function setMainContent(array $main_content) {
36     $this->mainContent = $main_content;
37     return $this;
38   }
39
40   /**
41    * {@inheritdoc}
42    */
43   public function setTitle($title) {
44     $this->title = $title;
45     return $this;
46   }
47
48   /**
49    * {@inheritdoc}
50    */
51   public function build() {
52     $build = [
53       'content' => [
54         'messages' => [
55           '#type' => 'status_messages',
56           '#weight' => -1000,
57         ],
58         'page_title' => [
59           '#type' => 'page_title',
60           '#title' => $this->title,
61           '#weight' => -900,
62         ],
63         'main_content' => ['#weight' => -800] + $this->mainContent,
64       ],
65     ];
66     return $build;
67   }
68
69 }