You are here

panopoly.install in Panopoly 8.2

Same filename and directory in other branches
  1. 7 panopoly.install

Install, update and uninstall hooks.

File

panopoly.install
View source
<?php

/**
 * @file
 * Install, update and uninstall hooks.
 */
use Drupal\panopoly\Installer\Form\PanopolyDemoInstallerForm;
use Drupal\user\Entity\Role;
use Drupal\user\Entity\User;
use Drupal\shortcut\Entity\Shortcut;

/**
 * Implements hook_install_tasks().
 */
function panopoly_install_tasks(&$install_tasks) {
  $tasks = [];

  // Add a task to install demo content.
  $tasks[PanopolyDemoInstallerForm::class] = [
    'display_name' => t('Install demo content'),
    'type' => 'form',
  ];

  // Add the Panopoly theme selection to the installation process.
  module_load_include('inc', 'panopoly_theme', 'panopoly_theme.profile');
  $tasks += panopoly_theme_profile_theme_selection_install_task($install_state);
  return $tasks;
}

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

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

  // Grant the 'use panopoly_search' permission to anonymous users by default.
  $role = Role::load(Role::ANONYMOUS_ID);
  $role
    ->grantPermission('use panopoly_search');
  $role
    ->save();

  // We install some menu links, so we have to rebuild the router, to ensure the
  // menu links are valid.
  \Drupal::service('router.builder')
    ->rebuildIfNeeded();

  // 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();
}

/**
 * Enables Panopoly Search.
 */
function panopoly_update_8001() {
  if (!\Drupal::moduleHandler()
    ->moduleExists('panopoly_search')) {

    /** @var \Drupal\Core\Extension\ModuleInstallerInterface $module_installer */
    $module_installer = \Drupal::service("module_installer");
    $module_installer
      ->install([
      'panopoly_search',
    ]);
  }
  $role = Role::load(Role::ANONYMOUS_ID);
  $role
    ->grantPermission('use panopoly_search');
  $role
    ->save();
}

Functions

Namesort descending Description
panopoly_install Implements hook_install().
panopoly_install_tasks Implements hook_install_tasks().
panopoly_update_8001 Enables Panopoly Search.