|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Drupal\df_tools_display\Plugin\DisplayVariant; |
|
4
|
|
|
|
|
5
|
|
|
use Drupal\Component\Utility\Html; |
|
6
|
|
|
use Drupal\Core\Form\FormStateInterface; |
|
7
|
|
|
use Drupal\page_manager\Plugin\DisplayVariant\PageBlockDisplayVariant; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Provides a display variant that simply contains blocks. |
|
11
|
|
|
* |
|
12
|
|
|
* @DisplayVariant( |
|
13
|
|
|
* id = "landing_display", |
|
14
|
|
|
* admin_label = @Translation("Landing page") |
|
15
|
|
|
* ) |
|
16
|
|
|
*/ |
|
17
|
|
|
class LandingDisplayVariant extends PageBlockDisplayVariant { |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @see \Drupal\page_manager\Plugin\PageBlockVariantInterface::getRegionNames() |
|
21
|
|
|
*/ |
|
22
|
|
|
public function getRegionNames() { |
|
23
|
|
|
return [ |
|
24
|
|
|
'top' => 'Top', |
|
25
|
|
|
'primary' => 'Primary', |
|
26
|
|
|
'secondary' => 'Secondary', |
|
27
|
|
|
'middle' => 'Middle', |
|
28
|
|
|
'sidebar' => 'Sidebar', |
|
29
|
|
|
'bottom' => 'Bottom', |
|
30
|
|
|
]; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* {@inheritdoc} |
|
35
|
|
|
*/ |
|
36
|
|
|
public function buildRegions(array $build) { |
|
37
|
|
|
// Get page_class configuration for our display variant. |
|
38
|
|
|
$class = Html::getClass($this->configuration['page_class']); |
|
39
|
|
|
if ($class == '') { |
|
40
|
|
|
$class = 'default'; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
// Append the prefix before buildRegions. |
|
44
|
|
|
$build['landing-top']['#prefix'] = '<div class="landing-display-' . $class . '">'; |
|
45
|
|
|
|
|
46
|
|
|
// Build the regions via PageBlockDisplayVariant::buildRegions. |
|
47
|
|
|
$build = parent::buildRegions($build); |
|
48
|
|
|
|
|
49
|
|
|
// Add suffix for wrapper after buildRegions. |
|
50
|
|
|
$build['landing-bottom']['#suffix'] = '</div>'; |
|
51
|
|
|
|
|
52
|
|
|
return $build; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* {@inheritdoc} |
|
57
|
|
|
*/ |
|
58
|
|
|
public function buildConfigurationForm(array $form, FormStateInterface $form_state) { |
|
59
|
|
|
$form = parent::buildConfigurationForm($form, $form_state); |
|
60
|
|
|
|
|
61
|
|
|
// Allow to configure the variant class, even when adding a new display. |
|
62
|
|
|
$form['page_class'] = [ |
|
63
|
|
|
'#type' => 'textfield', |
|
64
|
|
|
'#title' => $this->t('Page class'), |
|
65
|
|
|
'#description' => $this->t('Configure the wrapper class that will be used for this display.'), |
|
66
|
|
|
'#default_value' => $this->configuration['page_class'] ?: '', |
|
67
|
|
|
]; |
|
68
|
|
|
|
|
69
|
|
|
return $form; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* {@inheritdoc} |
|
74
|
|
|
*/ |
|
75
|
|
|
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { |
|
76
|
|
|
parent::submitConfigurationForm($form, $form_state); |
|
77
|
|
|
|
|
78
|
|
|
if ($form_state->hasValue('page_class')) { |
|
79
|
|
|
$this->configuration['page_class'] = $form_state->getValue('page_class'); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* {@inheritdoc} |
|
85
|
|
|
*/ |
|
86
|
|
|
public function defaultConfiguration() { |
|
87
|
|
|
return parent::defaultConfiguration() + [ |
|
88
|
|
|
'page_class' => '', |
|
89
|
|
|
]; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* {@inheritdoc} |
|
94
|
|
|
*/ |
|
95
|
|
|
protected function renderPageTitle($page_title) { |
|
96
|
|
|
$markup = parent::renderPageTitle($page_title); |
|
97
|
|
|
return $this->t((string) $markup); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
} |
|
101
|
|
|
|