forked from srijanone/ezcontent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathezcontent.profile
109 lines (99 loc) · 2.95 KB
/
ezcontent.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
<?php
/**
* @file
* Enables modules and site configuration for a standard site installation.
*/
use Drupal\Core\Entity\EntityFormInterface;
use Drupal\Core\Form\FormStateInterface;
/**
* Implements hook_install_tasks().
*/
function ezcontent_install_tasks(&$install_state) {
$tasks = [];
/*
If (empty($install_state['config_install_path'])) {
$tasks['ezcontent_module_configure_form'] = [
'display_name' => t('Configure additional modules'),
'type' => 'form',
'function' => 'Drupal\ezcontent\Installer\Form\ModuleConfigureForm',
];
$tasks['ezcontent_module_install'] = [
'display_name' => t('Install additional modules'),
'type' => 'batch',
];
}
*/
return $tasks;
}
/**
* Installs the ezcontent modules in a batch.
*
* @param array $install_state
* The install state.
*
* @return array
* A batch array to execute.
*/
function ezcontent_module_install(array &$install_state) {
$modules = $install_state['ezcontent_additional_modules'];
$batch = [];
if ($modules) {
$operations = [];
foreach ($modules as $module) {
$operations[] = [
'_ezcontent_install_module_batch',
[[$module], $module, $install_state['form_state_values']],
];
}
$batch = [
'operations' => $operations,
'title' => t('Installing additional modules'),
'error_message' => t('The installation has encountered an error.'),
];
}
return $batch;
}
/**
* Implements callback_batch_operation().
*
* Performs batch installation of modules.
*/
function _ezcontent_install_module_batch($module, $module_name, $form_values, &$context) {
set_time_limit(0);
try {
\Drupal::service('module_installer')->install($module, TRUE);
}
catch (\Exception $e) {
\Drupal::logger('ezcontent')->error($e->getMessage());
}
$context['results'][] = $module;
$context['message'] = t('Installed %module_name modules.', ['%module_name' => $module_name]);
}
/**
* Implements hook_themes_installed().
*/
function ezcontent_themes_installed($theme_list) {
if (in_array('ezcontent_amp', $theme_list)) {
// Install AMP module.
\Drupal::service('module_installer')->install(['amp'], TRUE);
// Use EZContent AMP theme as the theme in AMP settings.
$amp_theme_config = \Drupal::configFactory()->getEditable('amp.theme');
$amp_theme = $amp_theme_config->get('amptheme');
if (empty($amp_theme) || $amp_theme !== 'ezcontent_amp') {
$amp_theme_config->set('amptheme', 'ezcontent_amp')
->save(TRUE);
}
}
}
/**
* Implements hook_form_alter().
*/
function ezcontent_form_alter(array &$form, FormStateInterface $form_state, $form_id) {
if ($form_state->getFormObject() instanceof EntityFormInterface) {
$entityType = $form_state->getFormObject()->getEntity()->bundle();
$entityHideObj = \Drupal::config('ezcontent.settings')->getRawData();
if (isset($entityHideObj[$entityType]) && $entityHideObj[$entityType]) {
$form['revision_information']['#access'] = FALSE;
}
}
}