summaryrefslogtreecommitdiffstats
path: root/core/profiles/standard/standard.install
blob: b9d1c02dbea3a62d2d3c1e2e8a0c2c4fb03d2c70 (plain)
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
<?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() {
  // 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);

  // 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::moduleHandler()->invokeAll('permission')));
  // 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();

  // Create a Home link in the main menu.
  $menu_link = entity_create('menu_link', array(
    'link_title' => t('Home'),
    'link_path' => '<front>',
    'menu_name' => 'main',
  ));
  $menu_link->save();

  // Enable the Contact link in the footer menu.
  menu_link_maintain('contact', 'enable', 'contact');
  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();
}