drupal/core/profiles/standard/standard.install

83 lines
3.0 KiB
Plaintext
Raw Normal View History

<?php
/**
* @file
* Install, update and uninstall functions for the standard installation profile.
*/
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
/**
* Implements hook_install().
*
* Perform actions to set up the site for this profile.
*
* @see system_install()
*/
function standard_install() {
// Now that all modules are installed, make sure the entity storage and other
// handlers are up to date with the current entity and field definitions. For
// example, Path module adds a base field to nodes and taxonomy terms after
// those modules are already installed.
\Drupal::service('entity.definition_update_manager')->applyUpdates();
// Set front page to "node".
\Drupal::config('system.site')->set('page.front', 'node')->save();
// Add comment field to article node type.
\Drupal::service('comment.manager')->addDefaultField('node', 'article', 'comment', CommentItemInterface::OPEN);
// Hide the comment field in the rss view mode.
entity_get_display('node', 'article', 'rss')
->removeComponent('comment')
->save();
// Allow visitor account creation with administrative approval.
$user_settings = \Drupal::config('user.settings');
$user_settings->set('register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL)->save();
// Enable default permissions for system roles.
user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access comments'));
user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array('access comments', 'post comments', 'skip comment approval'));
// Enable all permissions for the administrator role.
user_role_grant_permissions('administrator', array_keys(\Drupal::service('user.permissions')->getPermissions()));
// Set this as the administrator role.
$user_settings->set('admin_role', 'administrator')->save();
// Assign user 1 the "administrator" role.
db_insert('users_roles')
->fields(array('uid' => 1, 'rid' => 'administrator'))
->execute();
// 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');
$menu_link_manager->updateDefinition('contact.site_page', array('enabled' => 1));
user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access site-wide contact form'));
user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array('access site-wide contact form'));
// Allow authenticated users to use shortcuts.
user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array('access shortcuts'));
// Populate the default shortcut set.
$shortcut = entity_create('shortcut', array(
'shortcut_set' => 'default',
'title' => t('Add content'),
'weight' => -20,
'path' => 'node/add',
));
$shortcut->save();
$shortcut = entity_create('shortcut', array(
'shortcut_set' => 'default',
'title' => t('All content'),
'weight' => -19,
'path' => 'admin/content',
));
$shortcut->save();
// Enable the admin theme.
\Drupal::config('node.settings')->set('use_admin_theme', '1')->save();
}