2015-08-17 17:00:26 -07:00
<?php
2016-10-06 15:16:20 -07:00
2015-08-17 17:00:26 -07:00
/**
* @file
* Install, update and uninstall functions for the standard installation profile.
*/
use Drupal\user\Entity\User;
use Drupal\user\RoleInterface;
2016-04-20 09:56:34 -07:00
use Drupal\shortcut\Entity\Shortcut;
2015-08-17 17:00:26 -07:00
/**
* Implements hook_install().
*
* Perform actions to set up the site for this profile.
*
* @see system_install()
*/
function standard_install() {
// Set front page to "node".
\Drupal::configFactory()->getEditable('system.site')->set('page.front', '/node')->save(TRUE);
// Allow visitor account creation with administrative approval.
$user_settings = \Drupal::configFactory()->getEditable('user.settings');
$user_settings->set('register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL)->save(TRUE);
// Enable default permissions for system roles.
2017-04-13 15:53:35 +01:00
user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, ['access comments']);
user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, ['access comments', 'post comments', 'skip comment approval']);
2015-08-17 17:00:26 -07:00
// Assign user 1 the "administrator" role.
$user = User::load(1);
$user->roles[] = 'administrator';
$user->save();
2016-04-20 09:56:34 -07:00
// We install some menu links, so we have to rebuild the router, to ensure the
// menu links are valid.
\Drupal::service('router.builder')->rebuildIfNeeded();
2015-08-17 17:00:26 -07:00
// Enable the Contact link in the footer menu.
/** @var \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager */
$menu_link_manager = \Drupal::service('plugin.manager.menu.link');
2017-04-13 15:53:35 +01:00
$menu_link_manager->updateDefinition('contact.site_page', ['enabled' => TRUE]);
2015-08-17 17:00:26 -07:00
2017-04-13 15:53:35 +01:00
user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, ['access site-wide contact form']);
user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, ['access site-wide contact form']);
2015-08-17 17:00:26 -07:00
// Allow authenticated users to use shortcuts.
2017-04-13 15:53:35 +01:00
user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, ['access shortcuts']);
2015-08-17 17:00:26 -07:00
// Populate the default shortcut set.
2017-04-13 15:53:35 +01:00
$shortcut = Shortcut::create([
2015-08-17 17:00:26 -07:00
'shortcut_set' => 'default',
'title' => t('Add content'),
'weight' => -20,
2017-04-13 15:53:35 +01:00
'link' => ['uri' => 'internal:/node/add'],
]);
2015-08-17 17:00:26 -07:00
$shortcut->save();
2017-04-13 15:53:35 +01:00
$shortcut = Shortcut::create([
2015-08-17 17:00:26 -07:00
'shortcut_set' => 'default',
'title' => t('All content'),
'weight' => -19,
2017-04-13 15:53:35 +01:00
'link' => ['uri' => 'internal:/admin/content'],
]);
2015-08-17 17:00:26 -07:00
$shortcut->save();
2015-10-08 11:40:12 -07:00
// Allow all users to use search.
2017-04-13 15:53:35 +01:00
user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, ['search content']);
user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, ['search content']);
2015-10-08 11:40:12 -07:00
2015-08-17 17:00:26 -07:00
// Enable the admin theme.
\Drupal::configFactory()->getEditable('node.settings')->set('use_admin_theme', TRUE)->save(TRUE);
}