Skip to content
Snippets Groups Projects
Forked from project / varbase
1008 commits behind the upstream repository.
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
varbase.install 15.73 KiB
<?php

/**
 * @file
 * Install, update and uninstall functions for the Varbase installation profile.
 */

use Symfony\Component\Yaml\Yaml;
use Drupal\user\Entity\User;
use Drupal\user\RoleInterface;
use Drupal\shortcut\Entity\Shortcut;

/**
 * Implements hook_install().
 *
 * Perform actions to set up the site for this profile.
 *
 * @see system_install()
 */
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');
  }
}

/**
 * Uninstall not needed feature modules as they had been moved to the profile.
 *
 * - varbase_user: Provide User related configuration. configs moved to profile.
 * - varbase_site: Provides site components. configs moved to profile.
 */
function varbase_update_8001() {

  // Read the extension configuration.
  $modules_data = \Drupal::config('core.extension')->get('module');

  // Unset the varbase_user feature module.
  if (isset($modules_data['varbase_user'])) {
    unset($modules_data['varbase_user']);
  }

  // Unset the varbase_site feature module.
  if (isset($modules_data['varbase_site'])) {
    unset($modules_data['varbase_site']);
  }

  // Save the configuration.
  \Drupal::configFactory()->getEditable('core.extension')->set('module', $modules_data)->save();

}

/**
 * Uninstall Layout plugin, then enables Layout Discovery.
 */
function varbase_update_8002() {
  if (\Drupal::moduleHandler()->moduleExists('layout_plugin')) {
    \Drupal::service('module_installer')->uninstall(['layout_plugin'], FALSE);
  }

  if (!\Drupal::moduleHandler()->moduleExists('layout_discovery')) {
    \Drupal::service('module_installer')->install(['layout_discovery'], FALSE);
  }
}

/**
 * Disable display suite switch view mode module.
 */
function varbase_update_8003() {
  if (\Drupal::moduleHandler()->moduleExists('ds_switch_view_mode')) {
    \Drupal::service('module_installer')->uninstall(['ds_switch_view_mode'], FALSE);
  }
}

/**
 * Enable node edit protection module.
 */
function varbase_update_8004() {
  if (!\Drupal::moduleHandler()->moduleExists('node_edit_protection')) {
    \Drupal::service('module_installer')->install(['node_edit_protection'], FALSE);
  }
}

/**
 * Enable Settings Tray module.
 */
function varbase_update_8005() {
  // Read the extension configuration.
  $modules_data = \Drupal::config('core.extension')->get('module');
  // Unset the outside_in module.
  if (isset($modules_data['outside_in'])) {
    unset($modules_data['outside_in']);
  }
  // Save the configuration.
  \Drupal::configFactory()->getEditable('core.extension')->set('module', $modules_data)->save();
  
  if (!\Drupal::moduleHandler()->moduleExists('settings_tray')) {
    \Drupal::service('module_installer')->install(['settings_tray'], FALSE);
  }
}

/**
 * Enable content lock module.
 */
function varbase_update_8006() {
  if (!\Drupal::moduleHandler()->moduleExists('content_lock')) {
    \Drupal::service('module_installer')->install(['content_lock'], FALSE);
  }
}

/**
 * Enable content lock timeout module.
 */
function varbase_update_8007() {
  if (!\Drupal::moduleHandler()->moduleExists('content_lock_timeout')) {
    \Drupal::service('module_installer')->install(['content_lock_timeout'], FALSE);
  }
}

/**
 * Enable entityqueue module.
 */
function varbase_update_8008() {
  if (!\Drupal::moduleHandler()->moduleExists('entityqueue')) {
    \Drupal::service('module_installer')->install(['entityqueue'], FALSE);
  }
}

/**
 * Enable Crop API module.
 */
function varbase_update_8009() {
  if (!\Drupal::moduleHandler()->moduleExists('crop')) {
    \Drupal::service('module_installer')->install(['crop'], FALSE);
  }
}

/**
 * Enable focal point module.
 */
function varbase_update_8010() {
  if (!\Drupal::moduleHandler()->moduleExists('focal_point')) {
    \Drupal::service('module_installer')->install(['focal_point'], FALSE);
  }
}

/**
 * Enable mail system module.
 */
function varbase_update_8011() {
  if (!\Drupal::moduleHandler()->moduleExists('mailsystem')) {
    \Drupal::service('module_installer')->install(['mailsystem'], FALSE);
  }
}

/**
 * Enable SMTP Authentication Support module.
 */
function varbase_update_8012() {
  if (!\Drupal::moduleHandler()->moduleExists('smtp')) {
    \Drupal::service('module_installer')->install(['smtp'], FALSE);
  }
}

/**
 * Enable DropzoneJS module.
 */
function varbase_update_8013() {
  if (!\Drupal::moduleHandler()->moduleExists('dropzonejs')) {
    \Drupal::service('module_installer')->install(['dropzonejs'], FALSE);
  }
}

/**
 * Enable DropzoneJS entity browser widget module.
 */
function varbase_update_8014() {
  if (!\Drupal::moduleHandler()->moduleExists('dropzonejs_eb_widget')) {
    \Drupal::service('module_installer')->install(['dropzonejs_eb_widget'], FALSE);
  }
}

/**
 * Enable Enhanced Entity Browser module.
 */
function varbase_update_8015() {
  if (!\Drupal::moduleHandler()->moduleExists('entity_browser_enhanced')) {
    \Drupal::service('module_installer')->install(['entity_browser_enhanced'], FALSE);
  }
}

/**
 * Enable Image Optimize (or ImageAPI Optimize) module.
 */
function varbase_update_8016() {
  if (!\Drupal::moduleHandler()->moduleExists('imageapi_optimize')) {
    \Drupal::service('module_installer')->install(['imageapi_optimize'], FALSE);
  }
}

/**
 * Enable Libraries module.
 */
function varbase_update_8017() {
  if (!\Drupal::moduleHandler()->moduleExists('libraries')) {
    \Drupal::service('module_installer')->install(['libraries'], FALSE);
  }
}

/**
 * Enable ACE Editor module.
 */
function varbase_update_8018() {
  if (!\Drupal::moduleHandler()->moduleExists('ace_editor')) {
    \Drupal::service('module_installer')->install(['ace_editor'], FALSE);
  }
}

/**
 * Enable Menu Block module.
 */
function varbase_update_8019() {
  if (!\Drupal::moduleHandler()->moduleExists('menu_block')) {
    \Drupal::service('module_installer')->install(['menu_block'], FALSE);
  }
}

/**
 * Enable Persistent Login module.
 */
function varbase_update_8020() {
  if (!\Drupal::moduleHandler()->moduleExists('persistent_login')) {
    \Drupal::service('module_installer')->install(['persistent_login'], FALSE);
  }
}

/**
 * Enable Rabbit Hole module.
 */
function varbase_update_8021() {
  if (!\Drupal::moduleHandler()->moduleExists('rabbit_hole')) {
    \Drupal::service('module_installer')->install(['rabbit_hole'], FALSE);
  }
}

/**
 * Enable Rabbit Hole nodes module.
 */
function varbase_update_8022() {
  if (!\Drupal::moduleHandler()->moduleExists('rh_node')) {
    \Drupal::service('module_installer')->install(['rh_node'], FALSE);
  }
}

/**
 * Enable Rabbit Hole taxonomy module.
 */
function varbase_update_8023() {
  if (!\Drupal::moduleHandler()->moduleExists('rh_taxonomy')) {
    \Drupal::service('module_installer')->install(['rh_taxonomy'], FALSE);
  }
}

/**
 * Enable Fast 404 module.
 */
function varbase_update_8024() {
  if (!\Drupal::moduleHandler()->moduleExists('fast404')) {
    \Drupal::service('module_installer')->install(['fast404'], FALSE);
  }
}

/**
 * Enable Views Bootstrap module.
 */
function varbase_update_8025() {
  if (!\Drupal::moduleHandler()->moduleExists('views_bootstrap')) {
    \Drupal::service('module_installer')->install(['views_bootstrap'], FALSE);
  }
}

/**
 * Enable Varbase Security module.
 */
function varbase_update_8026() {
  if (!\Drupal::moduleHandler()->moduleExists('varbase_security')) {
    \Drupal::service('module_installer')->install(['varbase_security'], FALSE);
  }
}

/**
 * Enable Varbase SEO module.
 */
function varbase_update_8027() {
  if (!\Drupal::moduleHandler()->moduleExists('varbase_seo')) {
    \Drupal::service('module_installer')->install(['varbase_seo'], FALSE);
  }
}

/**
 * Enable Max length module.
 */
function varbase_update_8028() {
  if (!\Drupal::moduleHandler()->moduleExists('maxlength')) {
    \Drupal::service('module_installer')->install(['maxlength'], FALSE);
  }
}

/**
 * Enable Menu position module.
 */
function varbase_update_8029() {
  if (!\Drupal::moduleHandler()->moduleExists('menu_position')) {
    \Drupal::service('module_installer')->install(['menu_position'], FALSE);
  }
}

/**
 * Enable Better Exposed Filters module.
 */
function varbase_update_8030() {
  if (!\Drupal::moduleHandler()->moduleExists('better_exposed_filters')) {
    \Drupal::service('module_installer')->install(['better_exposed_filters'], FALSE);
  }
}

/**
 * Enable Link Attributes widget module.
 */
function varbase_update_8031() {
  if (!\Drupal::moduleHandler()->moduleExists('link_attributes')) {
    \Drupal::service('module_installer')->install(['link_attributes'], FALSE);
  }
}

/**
 * Add Field Description.
 */
function varbase_update_8032() {
  $profile_path = drupal_get_path('profile', 'varbase') . '/config/install/';
  $configs['field.storage.block_content.field_description'] = $profile_path . 'field.storage.block_content.field_description.yml';
  $configs['field.storage.node.field_description'] = $profile_path . 'field.storage.node.field_description.yml';
  $configs['field.storage.taxonomy_term.field_description'] = $profile_path . 'field.storage.taxonomy_term.field_description.yml';

  foreach ($configs as $name => $config_path) {
    $data = (array) Yaml::parse($config_path);
    $config = \Drupal::configFactory()->getEditable($name);
    $config->setData($data)->save(TRUE);
  }
}

/**
 * Enabled "Create new revision" for Basic block.
 */
function varbase_update_8033() {
  $profile_path = drupal_get_path('profile', 'varbase') . '/config/install/';
  $config_path = $profile_path . 'block_content.type.basic.yml';
  $data = (array) Yaml::parse($config_path);
  $config = \Drupal::configFactory()->getEditable('block_content.type.basic');
  $config->setData($data)->save(TRUE);
}

/**
 * Enable Config Filter module.
 */
function varbase_update_8034() {
  if (!\Drupal::moduleHandler()->moduleExists('config_filter')) {
    \Drupal::service('module_installer')->install(['config_filter'], FALSE);
  }
}

/**
 * Enable Config Ignore module.
 */
function varbase_update_8035() {
  if (!\Drupal::moduleHandler()->moduleExists('config_ignore')) {
    \Drupal::service('module_installer')->install(['config_ignore'], FALSE);
  }
}

/**
 * Init config settings for which general config to ignore with config ignore.
 */
function varbase_update_8036() {
  $profile_path = drupal_get_path('profile', 'varbase') . '/config/install/';
  $config_path = $profile_path . 'config_ignore.settings.yml';
  $data = (array) Yaml::parse($config_path);
  $config = \Drupal::configFactory()->getEditable('config_ignore.settings');
  $config->setData($data)->save(TRUE);
}

/**
 * Enable Entityqueue Form Widget module.
 */
function varbase_update_8037() {
  if (!\Drupal::moduleHandler()->moduleExists('entityqueue_form_widget')) {
    \Drupal::service('module_installer')->install(['entityqueue_form_widget'], FALSE);
  }
}

/**
 * Enable Entity clone module.
 */
function varbase_update_8038() {
  if (!\Drupal::moduleHandler()->moduleExists('entity_clone')) {
    \Drupal::service('module_installer')->install(['entity_clone'], FALSE);
  }
}

/**
 * Enable Autocomplete Deluxe module.
 */
function varbase_update_8039() {
  if (!\Drupal::moduleHandler()->moduleExists('autocomplete_deluxe')) {
    \Drupal::service('module_installer')->install(['autocomplete_deluxe'], FALSE);
  }
}

/**
 * Add Color Configs to the Available styles for Varbase Bootstrap Paragraphs.
 */
function varbase_update_8040() {
  // 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);
  }
}

/**
 * Enable Varbase Tour module.
 */
function varbase_update_8041() {
  if (!\Drupal::moduleHandler()->moduleExists('varbase_tour')) {
    \Drupal::service('module_installer')->install(['varbase_tour'], FALSE);
  }
}

/**
 * Enable Settings Tray module as outside_in had been renamed settings_tray.
 */
function varbase_update_8042() {

  // Read the extension configuration.
  $modules_data = \Drupal::config('core.extension')->get('module');
  // Unset the outside_in module.
  if (isset($modules_data['outside_in'])) {
    unset($modules_data['outside_in']);
  }
  // Save the configuration.
  \Drupal::configFactory()->getEditable('core.extension')->set('module', $modules_data)->save();
  
  if (!\Drupal::moduleHandler()->moduleExists('settings_tray')) {
    \Drupal::service('module_installer')->install(['settings_tray'], FALSE);
  }
}