You are here

function varbase_install in Varbase: The Ultimate Drupal CMS Starter Kit (Bootstrap Ready) 8.5

Same name and namespace in other branches
  1. 8.8 varbase.install \varbase_install()
  2. 8.4 varbase.install \varbase_install()
  3. 8.6 varbase.install \varbase_install()
  4. 8.7 varbase.install \varbase_install()
  5. 7.3 varbase.install \varbase_install()
  6. 7 varbase.install \varbase_install()
  7. 7.2 varbase.install \varbase_install()
  8. 9.0.x varbase.install \varbase_install()

Implements hook_install().

Perform actions to set up the site for this profile.

See also

system_install()

File

./varbase.install, line 20
Install, update and uninstall functions for the Varbase installation profile.

Code

function varbase_install() {

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

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

  // Restrict user registration to admin role creation.
  \Drupal::configFactory()
    ->getEditable('user.settings')
    ->set('register', USER_REGISTER_ADMINISTRATORS_ONLY)
    ->save(TRUE);

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

  // Populate the default shortcut set.
  $shortcut = Shortcut::create(array(
    'shortcut_set' => 'default',
    'title' => t('Add content'),
    'weight' => 0,
    'link' => array(
      'uri' => 'internal:/node/add',
    ),
  ));
  $shortcut
    ->save();
  $shortcut = Shortcut::create(array(
    'shortcut_set' => 'default',
    'title' => t('All content'),
    'weight' => 1,
    'link' => array(
      'uri' => 'internal:/admin/content',
    ),
  ));
  $shortcut
    ->save();
  $shortcut = Shortcut::create(array(
    'shortcut_set' => 'default',
    'title' => t('All media'),
    'weight' => 2,
    'link' => array(
      'uri' => 'internal:/admin/content/media',
    ),
  ));
  $shortcut
    ->save();
  $shortcut = Shortcut::create(array(
    'shortcut_set' => 'default',
    'title' => t('Taxonomy'),
    'weight' => 3,
    'link' => array(
      'uri' => 'internal:/admin/structure/taxonomy',
    ),
  ));
  $shortcut
    ->save();
  $shortcut = Shortcut::create(array(
    'shortcut_set' => 'default',
    'title' => t('Permissions'),
    'weight' => 4,
    'link' => array(
      'uri' => 'internal:/admin/people/permissions',
    ),
  ));
  $shortcut
    ->save();

  // Allow all users to use search.
  user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, array(
    'search content',
  ));
  user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, array(
    'search content',
  ));

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

  // Entity updates to clear up any mismatched entity and/or field definitions
  // And Fix changes were detected in the entity type and field definitions.
  \Drupal::entityDefinitionUpdateManager()
    ->applyUpdates();

  // Activate Varbase Bootstrap Paragraphs Settings in the active config.
  if (\Drupal::moduleHandler()
    ->moduleExists('varbase_bootstrap_paragraphs')) {
    $profile_path = drupal_get_path('profile', 'varbase') . '/config/optional/';
    $config_path = $profile_path . 'varbase_bootstrap_paragraphs.settings.yml';
    $config_content = file_get_contents($config_path);
    $config_data = (array) Yaml::parse($config_content);
    $config_factory = \Drupal::configFactory()
      ->getEditable('varbase_bootstrap_paragraphs.settings');
    $config_factory
      ->setData($config_data)
      ->save(TRUE);
  }

  // If Varbase Tour were enabled then redirect to the homepage with activ tour.
  if (isset($GLOBALS['homepage_with_varbase_tour']) && $GLOBALS['homepage_with_varbase_tour'] == TRUE) {
    $homepage_with_tour = "/?tour";
    $response = new Symfony\Component\HttpFoundation\RedirectResponse($homepage_with_tour);
    $response
      ->send();
    exit;
    include_once __DIR__ . '/../../core/includes/install.core.inc';
    include_once __DIR__ . '/../../core/includes/install.inc';
    install_goto('?tour');
  }
}