You are here

commerce_kickstart.install in Commerce Kickstart 3.x

Same filename and directory in other branches
  1. 7.2 commerce_kickstart.install
  2. 7 commerce_kickstart.install

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

File

commerce_kickstart.install
View source
<?php

/**
 * @file
 * Install, update and uninstall functions for the commerce_base installation profile.
 */
use Drupal\shortcut\Entity\Shortcut;
use Drupal\user\Entity\User;
use Drupal\user\RoleInterface;
use Drupal\user\UserInterface;

/**
 * Implements hook_install().
 *
 * Perform actions to set up the site for this profile.
 *
 * @see system_install()
 */
function commerce_kickstart_install() {

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

  // Allow visitor account creation with administrative approval.
  $user_settings = \Drupal::configFactory()
    ->getEditable('user.settings');
  $user_settings
    ->set('register', UserInterface::REGISTER_VISITORS)
    ->set('verify_mail', FALSE)
    ->save(TRUE);

  // Enable default permissions for system roles.
  user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, [
    'access comments',
  ]);
  user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, [
    'access comments',
    'post comments',
    'skip comment approval',
  ]);

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

  // 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', [
    'enabled' => TRUE,
  ]);
  user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, [
    'access site-wide contact form',
  ]);
  user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, [
    'access site-wide contact form',
  ]);

  // Allow authenticated users to use shortcuts.
  user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, [
    'access shortcuts',
  ]);

  // Populate the default shortcut set.
  $shortcut = Shortcut::create([
    'shortcut_set' => 'default',
    'title' => t('Add content'),
    'weight' => -20,
    'link' => [
      'uri' => 'internal:/node/add',
    ],
  ]);
  $shortcut
    ->save();
  $shortcut = Shortcut::create([
    'shortcut_set' => 'default',
    'title' => t('All content'),
    'weight' => -19,
    'link' => [
      'uri' => 'internal:/admin/content',
    ],
  ]);
  $shortcut
    ->save();

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

/**
 * Implements hook_install_tasks_alter().
 */
function commerce_kickstart_install_tasks_alter(&$tasks, $install_state) {
  $tasks['install_finished']['function'] = 'commerce_kickstart_install_finished';
}

/**
 * Performs final installation steps and displays a 'finished' page.
 *
 * @param $install_state
 *   An array of information about the current installation state.
 */
function commerce_kickstart_install_finished(&$install_state) {
  install_finished($install_state);

  // Remove the Search API indexing messages, and all the other status messages.
  $messenger = \Drupal::service('messenger');
  $messenger
    ->deleteByType('status');
  $warning_messages = $messenger
    ->deleteByType('warning');
  $success_message = t('Congratulations, you installed @drupal!', [
    '@drupal' => drupal_install_profile_distribution_name(),
  ]);
  $messenger
    ->addMessage($success_message);

  // Re-add the warning messages (after the installation success message).
  foreach ($warning_messages as $warning_message) {
    $messenger
      ->addMessage($warning_message, 'warning');
  }
}

Functions

Namesort descending Description
commerce_kickstart_install Implements hook_install().
commerce_kickstart_install_finished Performs final installation steps and displays a 'finished' page.
commerce_kickstart_install_tasks_alter Implements hook_install_tasks_alter().