Newer
Older

Rajab Natshah
committed
/**
* @file
* Install, update and uninstall functions for the Varbase installation profile.
*/
use Symfony\Component\Yaml\Yaml;
use Drupal\user\Entity\User;
use Drupal\user\RoleInterface;
/**
* Implements hook_install().
*
* Perform actions to set up the site for this profile.
*
* @see system_install()
*/
function varbase_install() {
// Set front page to "node".
\Drupal::configFactory()->getEditable('system.site')->set('page.front', '/node')->save(TRUE);
// Assign user 1 the "administrator" role.
$user = User::load(1);
$user->roles[] = 'administrator';
$user->save();

Rajab Natshah
committed
// Restrict user registration to admin role creation.
\Drupal::configFactory()->getEditable('user.settings')->set('register', USER_REGISTER_ADMINISTRATORS_ONLY)->save(TRUE);
// Allow authenticated users to use shortcuts.
user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, ['access shortcuts']);

Rajab Natshah
committed
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
// Populate the default shortcut set.
$shortcut = Shortcut::create(array(
'shortcut_set' => 'default',
'title' => t('Add content'),
'weight' => 0,
'link' => array('uri' => 'internal:/node/add'),
));
$shortcut->save();
$shortcut = Shortcut::create(array(
'shortcut_set' => 'default',
'title' => t('All content'),
'weight' => 1,
'link' => array('uri' => 'internal:/admin/content'),
));
$shortcut->save();
$shortcut = Shortcut::create(array(
'shortcut_set' => 'default',
'title' => t('All media'),
'weight' => 2,
'link' => array('uri' => 'internal:/admin/content/media'),
));
$shortcut->save();
$shortcut = Shortcut::create(array(
'shortcut_set' => 'default',
'title' => t('Taxonomy'),
'weight' => 3,
'link' => array('uri' => 'internal:/admin/structure/taxonomy'),
));
$shortcut->save();
$shortcut = Shortcut::create(array(
'shortcut_set' => 'default',
'title' => t('Permissions'),
'weight' => 4,
'link' => array('uri' => 'internal:/admin/people/permissions'),
));
$shortcut->save();
// Allow all users to use search.
user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, array('search content'));
user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, array('search content'));
// Enable the admin theme.
\Drupal::configFactory()->getEditable('node.settings')->set('use_admin_theme', TRUE)->save(TRUE);

Rajab Natshah
committed

Rajab Natshah
committed
// Entity updates to clear up any mismatched entity and/or field definitions

Rajab Natshah
committed
// And Fix changes were detected in the entity type and field definitions.

Rajab Natshah
committed
\Drupal::entityDefinitionUpdateManager()->applyUpdates();
// Activate Varbase Bootstrap Paragraphs Settings in the active config.
if (\Drupal::moduleHandler()->moduleExists('varbase_bootstrap_paragraphs')) {
$profile_path = drupal_get_path('profile', 'varbase') . '/config/optional/';
$config_path = $profile_path . 'varbase_bootstrap_paragraphs.settings.yml';
$config_content = file_get_contents($config_path);
$config_data = (array) Yaml::parse($config_content);
$config_factory = \Drupal::configFactory()->getEditable('varbase_bootstrap_paragraphs.settings');
$config_factory->setData($config_data)->save(TRUE);
}

Rajab Natshah
committed
// If Varbase Tour were enabled then redirect to the homepage with activ tour.
if (isset($GLOBALS['homepage_with_varbase_tour'])
&& $GLOBALS['homepage_with_varbase_tour'] == TRUE) {
$homepage_with_tour = "/?tour";
$response = new Symfony\Component\HttpFoundation\RedirectResponse($homepage_with_tour);
$response->send();
exit;
include_once __DIR__ . '/../../core/includes/install.core.inc';
include_once __DIR__ . '/../../core/includes/install.inc';
install_goto('?tour');
}

Rajab Natshah
committed
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
/**
* Uninstall not needed feature modules as they had been moved to the profile.
*
* - varbase_user: Provide User related configuration. configs moved to profile.
* - varbase_site: Provides site components. configs moved to profile.
*/
function varbase_update_8001() {
// Read the extension configuration.
$modules_data = \Drupal::config('core.extension')->get('module');
// Unset the varbase_user feature module.
if (isset($modules_data['varbase_user'])) {
unset($modules_data['varbase_user']);
}
// Unset the varbase_site feature module.
if (isset($modules_data['varbase_site'])) {
unset($modules_data['varbase_site']);
}
// Save the configuration.
\Drupal::configFactory()->getEditable('core.extension')->set('module', $modules_data)->save();
}

Rajab Natshah
committed
/**
* Uninstall Layout plugin, then enables Layout Discovery.
*/
function varbase_update_8002() {
if (\Drupal::moduleHandler()->moduleExists('layout_plugin')) {
\Drupal::service('module_installer')->uninstall(['layout_plugin'], FALSE);
}

Rajab Natshah
committed

Rajab Natshah
committed
if (!\Drupal::moduleHandler()->moduleExists('layout_discovery')) {
\Drupal::service('module_installer')->install(['layout_discovery'], FALSE);
}
}

Rajab Natshah
committed
/**

Rajab Natshah
committed
* Disable display suite switch view mode module.

Rajab Natshah
committed
*/
function varbase_update_8003() {
if (\Drupal::moduleHandler()->moduleExists('ds_switch_view_mode')) {
\Drupal::service('module_installer')->uninstall(['ds_switch_view_mode'], FALSE);
}

Rajab Natshah
committed
}

Rajab Natshah
committed
/**
* Enable node edit protection module.
*/
function varbase_update_8004() {
if (!\Drupal::moduleHandler()->moduleExists('node_edit_protection')) {
\Drupal::service('module_installer')->install(['node_edit_protection'], FALSE);

Rajab Natshah
committed
}

Rajab Natshah
committed
}

Rajab Natshah
committed
/**
* Enable Settings Tray module.
*/
function varbase_update_8005() {

Rajab Natshah
committed
// Read the extension configuration.
$modules_data = \Drupal::config('core.extension')->get('module');
// Unset the outside_in module.
if (isset($modules_data['outside_in'])) {
unset($modules_data['outside_in']);
}
// Save the configuration.
\Drupal::configFactory()->getEditable('core.extension')->set('module', $modules_data)->save();
if (!\Drupal::moduleHandler()->moduleExists('settings_tray')) {
\Drupal::service('module_installer')->install(['settings_tray'], FALSE);

Rajab Natshah
committed
}

Rajab Natshah
committed
}

Rajab Natshah
committed
/**
* Enable content lock module.
*/
function varbase_update_8006() {

Rajab Natshah
committed
if (!\Drupal::moduleHandler()->moduleExists('content_lock')) {
\Drupal::service('module_installer')->install(['content_lock'], FALSE);
}

Rajab Natshah
committed
}

Rajab Natshah
committed
/**
* Enable content lock timeout module.
*/
function varbase_update_8007() {

Rajab Natshah
committed
if (!\Drupal::moduleHandler()->moduleExists('content_lock_timeout')) {
\Drupal::service('module_installer')->install(['content_lock_timeout'], FALSE);
}

Rajab Natshah
committed
}

Rajab Natshah
committed

Rajab Natshah
committed
/**
* Enable entityqueue module.
*/
function varbase_update_8008() {

Rajab Natshah
committed
if (!\Drupal::moduleHandler()->moduleExists('entityqueue')) {
\Drupal::service('module_installer')->install(['entityqueue'], FALSE);
}

Rajab Natshah
committed
}

Rajab Natshah
committed

Rajab Natshah
committed
/**
* Enable Crop API module.
*/
function varbase_update_8009() {

Rajab Natshah
committed
if (!\Drupal::moduleHandler()->moduleExists('crop')) {
\Drupal::service('module_installer')->install(['crop'], FALSE);
}

Rajab Natshah
committed
}

Rajab Natshah
committed

Rajab Natshah
committed
/**
* Enable focal point module.
*/
function varbase_update_8010() {

Rajab Natshah
committed
if (!\Drupal::moduleHandler()->moduleExists('focal_point')) {
\Drupal::service('module_installer')->install(['focal_point'], FALSE);
}

Rajab Natshah
committed
}

Rajab Natshah
committed

Rajab Natshah
committed
/**
* Enable mail system module.
*/
function varbase_update_8011() {

Rajab Natshah
committed
if (!\Drupal::moduleHandler()->moduleExists('mailsystem')) {
\Drupal::service('module_installer')->install(['mailsystem'], FALSE);
}

Rajab Natshah
committed
}

Rajab Natshah
committed

Rajab Natshah
committed
/**
* Enable SMTP Authentication Support module.
*/
function varbase_update_8012() {

Rajab Natshah
committed
if (!\Drupal::moduleHandler()->moduleExists('smtp')) {
\Drupal::service('module_installer')->install(['smtp'], FALSE);
}

Rajab Natshah
committed
}

Rajab Natshah
committed

Rajab Natshah
committed
/**
* Enable DropzoneJS module.
*/
function varbase_update_8013() {

Rajab Natshah
committed
if (!\Drupal::moduleHandler()->moduleExists('dropzonejs')) {
\Drupal::service('module_installer')->install(['dropzonejs'], FALSE);
}

Rajab Natshah
committed
}

Rajab Natshah
committed
/**
* Enable DropzoneJS entity browser widget module.
*/
function varbase_update_8014() {

Rajab Natshah
committed
if (!\Drupal::moduleHandler()->moduleExists('dropzonejs_eb_widget')) {
\Drupal::service('module_installer')->install(['dropzonejs_eb_widget'], FALSE);
}

Rajab Natshah
committed
}

Rajab Natshah
committed
/**
* Enable Enhanced Entity Browser module.
*/
function varbase_update_8015() {

Rajab Natshah
committed
if (!\Drupal::moduleHandler()->moduleExists('entity_browser_enhanced')) {
\Drupal::service('module_installer')->install(['entity_browser_enhanced'], FALSE);
}

Rajab Natshah
committed
}

Rajab Natshah
committed
/**
* Enable Image Optimize (or ImageAPI Optimize) module.
*/
function varbase_update_8016() {

Rajab Natshah
committed
if (!\Drupal::moduleHandler()->moduleExists('imageapi_optimize')) {
\Drupal::service('module_installer')->install(['imageapi_optimize'], FALSE);
}

Rajab Natshah
committed
}

Rajab Natshah
committed
/**
* Enable Libraries module.
*/
function varbase_update_8017() {

Rajab Natshah
committed
if (!\Drupal::moduleHandler()->moduleExists('libraries')) {
\Drupal::service('module_installer')->install(['libraries'], FALSE);
}

Rajab Natshah
committed
}
/**
* Enable ACE Editor module.
*/
function varbase_update_8018() {
if (!\Drupal::moduleHandler()->moduleExists('ace_editor')) {
\Drupal::service('module_installer')->install(['ace_editor'], FALSE);
}

Rajab Natshah
committed
}

Rajab Natshah
committed
/**
* Enable Menu Block module.
*/
function varbase_update_8019() {

Rajab Natshah
committed
if (!\Drupal::moduleHandler()->moduleExists('menu_block')) {
\Drupal::service('module_installer')->install(['menu_block'], FALSE);
}

Rajab Natshah
committed
}

Rajab Natshah
committed
/**
* Enable Persistent Login module.
*/
function varbase_update_8020() {

Rajab Natshah
committed
if (!\Drupal::moduleHandler()->moduleExists('persistent_login')) {
\Drupal::service('module_installer')->install(['persistent_login'], FALSE);
}

Rajab Natshah
committed
}

Rajab Natshah
committed
/**
* Enable Rabbit Hole module.
*/
function varbase_update_8021() {

Rajab Natshah
committed
if (!\Drupal::moduleHandler()->moduleExists('rabbit_hole')) {
\Drupal::service('module_installer')->install(['rabbit_hole'], FALSE);
}

Rajab Natshah
committed
}

Rajab Natshah
committed
/**
* Enable Rabbit Hole nodes module.
*/
function varbase_update_8022() {

Rajab Natshah
committed
if (!\Drupal::moduleHandler()->moduleExists('rh_node')) {
\Drupal::service('module_installer')->install(['rh_node'], FALSE);
}

Rajab Natshah
committed
}

Rajab Natshah
committed
/**
* Enable Rabbit Hole taxonomy module.
*/
function varbase_update_8023() {

Rajab Natshah
committed
if (!\Drupal::moduleHandler()->moduleExists('rh_taxonomy')) {
\Drupal::service('module_installer')->install(['rh_taxonomy'], FALSE);
}

Rajab Natshah
committed
}

Rajab Natshah
committed
/**
* Enable Fast 404 module.
*/
function varbase_update_8024() {

Rajab Natshah
committed
if (!\Drupal::moduleHandler()->moduleExists('fast404')) {
\Drupal::service('module_installer')->install(['fast404'], FALSE);
}

Rajab Natshah
committed
}

Rajab Natshah
committed
/**
* Enable Views Bootstrap module.
*/
function varbase_update_8025() {

Rajab Natshah
committed
if (!\Drupal::moduleHandler()->moduleExists('views_bootstrap')) {
\Drupal::service('module_installer')->install(['views_bootstrap'], FALSE);
}

Rajab Natshah
committed
}

Rajab Natshah
committed
/**
* Enable Varbase Security module.
*/
function varbase_update_8026() {

Rajab Natshah
committed
if (!\Drupal::moduleHandler()->moduleExists('varbase_security')) {
\Drupal::service('module_installer')->install(['varbase_security'], FALSE);
}

Rajab Natshah
committed
}

Rajab Natshah
committed
/**
* Enable Varbase SEO module.
*/
function varbase_update_8027() {

Rajab Natshah
committed
if (!\Drupal::moduleHandler()->moduleExists('varbase_seo')) {
\Drupal::service('module_installer')->install(['varbase_seo'], FALSE);
}

Rajab Natshah
committed
}

Rajab Natshah
committed
/**
* Enable Max length module.
*/
function varbase_update_8028() {
if (!\Drupal::moduleHandler()->moduleExists('maxlength')) {
\Drupal::service('module_installer')->install(['maxlength'], FALSE);
}

Rajab Natshah
committed
}

Rajab Natshah
committed
/**
* Enable Menu position module.
*/
function varbase_update_8029() {
if (!\Drupal::moduleHandler()->moduleExists('menu_position')) {
\Drupal::service('module_installer')->install(['menu_position'], FALSE);
}

Rajab Natshah
committed
}

Rajab Natshah
committed
/**
* Enable Better Exposed Filters module.
*/
function varbase_update_8030() {
if (!\Drupal::moduleHandler()->moduleExists('better_exposed_filters')) {
\Drupal::service('module_installer')->install(['better_exposed_filters'], FALSE);
}

Rajab Natshah
committed
}

Rajab Natshah
committed
/**
* Enable Link Attributes widget module.
*/
function varbase_update_8031() {
if (!\Drupal::moduleHandler()->moduleExists('link_attributes')) {
\Drupal::service('module_installer')->install(['link_attributes'], FALSE);
}

Rajab Natshah
committed
}

Rajab Natshah
committed
/**
* Add Field Description.
*/
function varbase_update_8032() {
$profile_path = drupal_get_path('profile', 'varbase') . '/config/install/';
$configs['field.storage.block_content.field_description'] = $profile_path . 'field.storage.block_content.field_description.yml';
$configs['field.storage.node.field_description'] = $profile_path . 'field.storage.node.field_description.yml';
$configs['field.storage.taxonomy_term.field_description'] = $profile_path . 'field.storage.taxonomy_term.field_description.yml';
foreach ($configs as $name => $config_path) {
$data = (array) Yaml::parse($config_path);
$config = \Drupal::configFactory()->getEditable($name);
$config->setData($data)->save(TRUE);
}

Rajab Natshah
committed
}

Rajab Natshah
committed
/**
* Enabled "Create new revision" for Basic block.
*/
function varbase_update_8033() {
$profile_path = drupal_get_path('profile', 'varbase') . '/config/install/';
$config_path = $profile_path . 'block_content.type.basic.yml';
$data = (array) Yaml::parse($config_path);
$config = \Drupal::configFactory()->getEditable('block_content.type.basic');
$config->setData($data)->save(TRUE);
}
/**
* Enable Config Filter module.
*/
function varbase_update_8034() {
if (!\Drupal::moduleHandler()->moduleExists('config_filter')) {
\Drupal::service('module_installer')->install(['config_filter'], FALSE);
}
}
/**
* Enable Config Ignore module.
*/
function varbase_update_8035() {
if (!\Drupal::moduleHandler()->moduleExists('config_ignore')) {
\Drupal::service('module_installer')->install(['config_ignore'], FALSE);
}
}
/**
* Init config settings for which general config to ignore with config ignore.
*/
function varbase_update_8036() {
$profile_path = drupal_get_path('profile', 'varbase') . '/config/install/';
$config_path = $profile_path . 'config_ignore.settings.yml';
$data = (array) Yaml::parse($config_path);
$config = \Drupal::configFactory()->getEditable('config_ignore.settings');
$config->setData($data)->save(TRUE);
}

Yasmeen Abuerrub
committed
/**
* Enable Entityqueue Form Widget module.
*/
function varbase_update_8037() {
if (!\Drupal::moduleHandler()->moduleExists('entityqueue_form_widget')) {
\Drupal::service('module_installer')->install(['entityqueue_form_widget'], FALSE);
}
}

Yasmeen Abuerrub
committed
/**
* Enable Entity clone module.
*/
function varbase_update_8038() {
if (!\Drupal::moduleHandler()->moduleExists('entity_clone')) {
\Drupal::service('module_installer')->install(['entity_clone'], FALSE);
}
}
/**
* Enable Autocomplete Deluxe module.
*/
function varbase_update_8039() {
if (!\Drupal::moduleHandler()->moduleExists('autocomplete_deluxe')) {
\Drupal::service('module_installer')->install(['autocomplete_deluxe'], FALSE);
}
}

Rajab Natshah
committed
/**

Rajab Natshah
committed
* Add Color Configs to the Available styles for Varbase Bootstrap Paragraphs.

Rajab Natshah
committed
*/
function varbase_update_8040() {
// Activate Varbase Bootstrap Paragraphs Settings in the active config.
if (\Drupal::moduleHandler()->moduleExists('varbase_bootstrap_paragraphs')) {
$profile_path = drupal_get_path('profile', 'varbase') . '/config/optional/';
$config_path = $profile_path . 'varbase_bootstrap_paragraphs.settings.yml';
$config_content = file_get_contents($config_path);
$config_data = (array) Yaml::parse($config_content);
$config_factory = \Drupal::configFactory()->getEditable('varbase_bootstrap_paragraphs.settings');
$config_factory->setData($config_data)->save(TRUE);
}

Rajab Natshah
committed
}

Rajab Natshah
committed
/**
* Enable Varbase Tour module.
*/
function varbase_update_8041() {
if (!\Drupal::moduleHandler()->moduleExists('varbase_tour')) {
\Drupal::service('module_installer')->install(['varbase_tour'], FALSE);
}

Rajab Natshah
committed
}
/**
* Enable Settings Tray module as outside_in had been renamed settings_tray.
*/
function varbase_update_8042() {

Rajab Natshah
committed
// Read the extension configuration.
$modules_data = \Drupal::config('core.extension')->get('module');
// Unset the outside_in module.
if (isset($modules_data['outside_in'])) {
unset($modules_data['outside_in']);

Rajab Natshah
committed
}

Rajab Natshah
committed
// Save the configuration.
\Drupal::configFactory()->getEditable('core.extension')->set('module', $modules_data)->save();

Rajab Natshah
committed
if (!\Drupal::moduleHandler()->moduleExists('settings_tray')) {
\Drupal::service('module_installer')->install(['settings_tray'], FALSE);
}
}