You are here

bear.install in Bear 8

Same filename and directory in other branches
  1. 8.2 bear.install
  2. 7.2 bear.install
  3. 7 bear.install

Install, update and uninstall functions for the bear installation profile.

File

bear.install
View source
<?php

/**
 * @file
 * Install, update and uninstall functions for the bear installation profile.
 */
use Drupal\user\Entity\User;
use Drupal\user\RoleInterface;
use Drupal\user\Entity\Role;

/**
 * Implements hook_install().
 *
 * Perform actions to set up the site for this profile.
 *
 * @see system_install()
 */
function bear_install() {
  _bear_setup_base_configurations();
  _bear_enable_modules();
  _bear_setup_users_and_roles();
  _bear_setup_themes();
}

/**
 * Setup base site configurations.
 */
function _bear_setup_base_configurations() {

  // Set front page to "node".
  \Drupal::configFactory()
    ->getEditable('system.site')
    ->set('page.front', '/node')
    ->save(TRUE);
}

/**
 * Enable modules by default.
 */
function _bear_enable_modules() {

  // Install devel submodules.
  \Drupal::service('module_installer')
    ->install([
    'devel',
    'kint',
  ], TRUE);
}

/**
 * Setup default users and roles.
 */
function _bear_setup_users_and_roles() {

  // 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.
  user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, array(
    'use text format basic_html',
  ));
  user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, array(
    'use text format basic_html',
  ));

  // Assign user 1 the "administrator" role.
  $user = User::load(1);
  $user->roles[] = 'administrator';
  $user
    ->save();
  _bear_setup_role_editor();
}

/**
 * Setup the editor role.
 */
function _bear_setup_role_editor() {
  user_role_grant_permissions('editor', array(
    'access administration pages',
    'access coffee',
    'access content overview',
    'access in-place editing',
    'access toolbar',
    'administer menu',
    'administer nodes',
    'administer url aliases',
    'administer users',
    'bypass node access',
    'change own username',
    'create url aliases',
    'delete all revisions',
    'edit field help text',
    'revert all revisions',
    'use text format basic_html',
    'use text format full_html',
    'view all revisions',
    'view the administration theme',
  ));
}

/**
 * Setup the themes.
 */
function _bear_setup_themes() {

  // Enable the admin theme.
  \Drupal::configFactory()
    ->getEditable('node.settings')
    ->set('use_admin_theme', TRUE)
    ->save(TRUE);
}

Functions

Namesort descending Description
bear_install Implements hook_install().
_bear_enable_modules Enable modules by default.
_bear_setup_base_configurations Setup base site configurations.
_bear_setup_role_editor Setup the editor role.
_bear_setup_themes Setup the themes.
_bear_setup_users_and_roles Setup default users and roles.