-
Notifications
You must be signed in to change notification settings - Fork 129
/
weeshop.profile
138 lines (127 loc) · 3.95 KB
/
weeshop.profile
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
<?php
/**
* @file
* Enables modules and site configuration for a commerce_base site installation.
*/
use Drupal\contact\Entity\ContactForm;
use Drupal\Core\Entity\EntityStorageException;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
/**
* Implements hook_install_tasks().
*/
function weeshop_install_tasks(&$install_state): array {
return [
'_weeshop_final_site_setup' => [
'display_name' => t('Data Importing'),
'type' => 'batch',
'display' => TRUE,
],
];
}
/**
* Implements hook_form_FORM_ID_alter() for install_configure_form().
*
* Allows the profile to alter the site configuration form.
*/
function weeshop_form_install_configure_form_alter(&$form, FormStateInterface $form_state): void {
// Add a placeholder as example that one can choose an arbitrary site name.
$form['site_information']['site_name']['#attributes']['placeholder'] = t('Your WeeShop site name');
// Add 'Social' fieldset and options.
$form['weeshop'] = [
'#type' => 'fieldgroup',
'#title' => t('WeeShop Demo data'),
'#description' => t('If you want to have demo data within your new site, please check the yes.'),
'#weight' => 50,
];
// Checkboxes to generate demo content.
$form['weeshop']['demo_content'] = [
'#type' => 'checkbox',
'#title' => t('Generate demo content'),
'#description' => t('Will generate files, products, adverts.'),
];
$form['#submit'][] = 'weeshop_form_install_configure_submit';
}
/**
* Submission handler to sync the contact.form.feedback recipient.
*/
function weeshop_form_install_configure_submit($form, FormStateInterface $form_state): void {
Drupal::state()->set('weeshop_install_demo_content', $form_state->getValue('demo_content'));
$site_mail = $form_state->getValue('site_mail');
try {
ContactForm::load('feedback')->setRecipients([$site_mail])->trustData()->save();
}
catch (EntityStorageException $e) {
Drupal::messenger()->addError(t('Saving setting of contact form module occurs error. :error', [
':error' => $e->getMessage(),
]));
}
}
/**
* Implements hook_views_plugins_row_alter().
*/
function weeshop_views_plugins_row_alter(array &$plugins): void {
// Just expose the data entity row for entity views.
foreach (Drupal::entityTypeManager()->getDefinitions() as $entity_type) {
$tables = array_filter([
$entity_type->getBaseTable(),
$entity_type->getDataTable(),
$entity_type->getRevisionTable(),
$entity_type->getRevisionDataTable(),
]);
$plugins['data_entity']['base'] = $plugins['data_entity']['base'] ?? [];
$plugins['data_entity']['base'] = array_merge($plugins['data_entity']['base'], $tables);
}
}
/**
* Implements hook_toolbar().
*
* Add WeeShop logo to the toolbar.
*/
function weeshop_toolbar(): array {
$items = [];
$items['weeshop'] = [
'#type' => 'toolbar_item',
'tab' => [
'#type' => 'link',
'#title' => t('WeeShop'),
'#url' => Url::fromRoute('<front>'),
'#options' => [
'attributes' => [
'title' => t('WeeShop'),
'class' => ['toolbar-item', 'toolbar-icon'],
'id' => 'admin-logo',
],
],
],
'#attached' => [
'library' => [
'weeshop/admin-logo',
],
],
'#weight' => -90,
];
return $items;
}
/**
* Import demo data after installation.
*
* @param array $install_state
* Installation state data.
*
* @return array
* Return the batch definition.
*/
function _weeshop_final_site_setup(array &$install_state): array {
Drupal::logger('weeshop_demo')->notice('Executing _weeshop_final_site_setup()');
$batch_operations = [];
$demo_content = Drupal::state()->get('weeshop_install_demo_content');
Drupal::logger('weeshop_demo')->notice('Value of $demo_content is ' . $demo_content);
if ($demo_content === 1) {
$batch_operations[] = ['_weeshop_demo_execute_migrations', ['import']];
}
return [
'title' => t('Importing data'),
'operations' => $batch_operations,
];
}