-
Notifications
You must be signed in to change notification settings - Fork 1
/
c2distro.install
139 lines (126 loc) · 3.84 KB
/
c2distro.install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?php
/**
* @file
* Install, update and uninstall functions for the c2distro install profile.
*/
use Drupal\block\Entity\Block;
use Drupal\menu_link_content\Entity\MenuLinkContent;
/**
* Implements hook_install().
*
* Perform actions to set up the site for this profile.
*
* @see system_install()
*/
function c2distro_install() {
// Enable the demo content module. This can't be specified as a dependency
// in the c2distro.info.yml file, as it requires configuration provided by
// the profile (fields etc.).
\Drupal::service('module_installer')->install(['c2distro_default_content'], TRUE);
// Create a menu link.
$home_page = \Drupal::entityTypeManager()->getStorage('node')->loadByProperties([
'title' => 'Home page',
]);
$home_page = reset($home_page);
MenuLinkContent::create([
'title' => 'Home page',
'link' => ['uri' => 'internal:/node/' . $home_page->id()],
'menu_name' => 'main',
'weight' => 10,
])->save();
// Set the default front page.
\Drupal::configFactory()
->getEditable('system.site')
->set('page.front', '/node/' . $home_page->id())
->save();
// Create the Events menu item with Events and Calendar sub-menu links.
$menu_link_content = MenuLinkContent::create([
'title' => 'Events',
'link' => ['uri' => 'route:<nolink>'],
'menu_name' => 'main',
'expanded' => TRUE,
'weight' => 40,
]);
$menu_link_content->save();
$mid = $menu_link_content->getPluginId();
MenuLinkContent::create([
'title' => 'Events',
'link' => ['uri' => 'internal:/events'],
'menu_name' => 'main',
'parent' => $mid,
'weight' => 10,
])->save();
MenuLinkContent::create([
'title' => 'Calendar',
'link' => ['uri' => 'internal:/calendar'],
'menu_name' => 'main',
'parent' => $mid,
'weight' => 20,
])->save();
// Create a Contact us footer menu link.
MenuLinkContent::create([
'title' => 'Contact us',
'link' => ['uri' => 'mailto:contact@example.com'],
'menu_name' => 'footer',
'weight' => 100,
])->save();
// Place the HP hero custom content block.
_c2distro_place_the_hp_hero_block();
// Place the Footer custom content block.
_c2distro_place_the_footer_block_content();
// Place the Selector cards block to the Resources page.
_c2distro_place_selector_cards_block();
}
/**
* Place the HP hero custom content block.
*/
function _c2distro_place_the_hp_hero_block() {
$values = [
'id' => 'hphero',
'plugin' => 'block_content:19284f87-8ad9-4c7d-bac2-01ec669b41f1',
'region' => 'top',
'theme' => 'c2d_theme',
'weight' => 0,
];
$block = Block::create($values);
$visibility['request_path']['pages'] = '<front>';
$block->setVisibilityConfig('request_path', $visibility['request_path']);
$block->save();
}
/**
* Place the Footer custom content block.
*/
function _c2distro_place_the_footer_block_content() {
$values = [
'id' => 'footerblockcontent',
'plugin' => 'block_content:f0ba0b00-072c-4c7d-ae22-89b9fd58a635',
'region' => 'footer',
'theme' => 'c2d_theme',
'weight' => 0,
];
$block = Block::create($values);
$block->save();
}
/**
* Place the Selector cards block to the Resources page.
*/
function _c2distro_place_selector_cards_block() {
$resources_page = \Drupal::entityTypeManager()->getStorage('node')->loadByProperties([
'title' => 'Resources',
]);
$resources_page = reset($resources_page);
$values = [
'id' => 'views_block__selector_cards_selector_cards_block',
'plugin' => 'views_block:selector_cards-selector_cards_block',
'region' => 'bottom',
'theme' => 'c2d_theme',
'weight' => 0,
'settings' => [
'label_display' => FALSE,
],
];
$block = Block::create($values);
$visibility['request_path']['pages'] = '/node/' . $resources_page->id();
$block->setVisibilityConfig('request_path', $visibility['request_path']);
$block->save();
}