govcms-2.x-dev/govcms.install
govcms.install
<?php
/**
* @file
* Install, update and uninstall functions for the GovCMS installation profile.
*/
use Drupal\node\Entity\Node;
use Drupal\shortcut\Entity\Shortcut;
use Drupal\menu_link_content\Entity\MenuLinkContent;
/**
* Define a default theme constant.
*/
define('GOVCMS_DEFAULT_THEME', 'govcms_bartik');
/**
* Define the admin theme.
*/
define('GOVCMS_DEFAULT_ADMIN_THEME', 'claro');
/**
* Implements hook_install().
*
* Perform actions to set up the site for GovCMS Profile.
*
* @see system_install()
*/
function govcms_install() {
// Restrict user registration to admin role creation.
\Drupal::configFactory()
->getEditable('user.settings')
->set('register', \Drupal\user\UserInterface::REGISTER_ADMINISTRATORS_ONLY)
->save(TRUE);
// Populate the default shortcut set.
Shortcut::create(
[
'shortcut_set' => 'default',
'title' => t('Add content'),
'weight' => 1,
'link' => ['uri' => 'internal:/node/add'],
]
)->save();
MenuLinkContent::create(
[
'title' => 'Accessibility',
'link' => ['uri' => 'https://www.govcms.gov.au'],
'menu_name' => 'footer',
]
)->save();
MenuLinkContent::create(
[
'title' => 'Copyright',
'link' => ['uri' => 'https://www.govcms.gov.au'],
'menu_name' => 'footer',
]
)->save();
MenuLinkContent::create(
[
'title' => 'Disclaimers',
'link' => ['uri' => 'https://www.govcms.gov.au'],
'menu_name' => 'footer',
]
)->save();
MenuLinkContent::create(
[
'title' => 'Privacy',
'link' => ['uri' => 'https://www.govcms.gov.au'],
'menu_name' => 'footer',
]
)->save();
MenuLinkContent::create([
'title' => 'Our community',
'link' => ['uri' => 'https://www.govcms.gov.au/our-community'],
'menu_name' => 'govcms-community',
])->save();
MenuLinkContent::create([
'title' => 'About GovCMS',
'link' => ['uri' => 'https://www.govcms.gov.au/about'],
'menu_name' => 'govcms-about',
])->save();
// Don't do anything else during config sync.
if (\Drupal::isConfigSyncing()) {
return;
}
// Set front page to "node".
\Drupal::configFactory()
->getEditable('system.site')
->set('page.front', '/node')
->save(TRUE);
// Set the default and admin theme.
\Drupal::configFactory()
->getEditable('system.theme')
->set('default', GOVCMS_DEFAULT_THEME)
->set('admin', GOVCMS_DEFAULT_ADMIN_THEME)
->save(TRUE);
// Enable the admin theme.
\Drupal::configFactory()
->getEditable('node.settings')
->set('use_admin_theme', TRUE)
->save(TRUE);
// Set the path to the logo, favicon and README file based on install directory.
$govcms_path = drupal_get_path('profile', 'govcms');
\Drupal::configFactory()
->getEditable('system.theme.global')
->set('logo', [
'path' => $govcms_path . '/logo.svg',
'url' => '',
'use_default' => TRUE,
])
->set('favicon', [
'mimetype' => 'image/vnd.microsoft.icon',
'path' => $govcms_path . '/favicon.ico',
'url' => '',
'use_default' => FALSE,
])
->save(TRUE);
drupal_flush_all_caches();
}
