5 * Determine default settings for Drupal 8.
8 if (!defined('CIVI_SETUP')) {
9 exit("Installation plugins must only be loaded by the installer.\n");
12 \Civi\Setup
::dispatcher()
13 ->addListener('civi.setup.checkAuthorized', function (\Civi\Setup\Event\CheckAuthorizedEvent
$e) {
14 $model = $e->getModel();
15 if ($model->cms
!== 'Drupal8' ||
!is_callable(['Drupal', 'currentUser'])) {
19 \Civi\Setup
::log()->info(sprintf('[%s] Handle %s', basename(__FILE__
), 'checkAuthorized'));
20 $e->setAuthorized(\Civi\Setup\DrupalUtil
::isDrush() || \Drupal
::currentUser()->hasPermission('administer modules'));
23 \Civi\Setup
::dispatcher()
24 ->addListener('civi.setup.init', function (\Civi\Setup\Event\InitEvent
$e) {
25 $model = $e->getModel();
26 if ($model->cms
!== 'Drupal8' ||
!is_callable(['Drupal', 'currentUser'])) {
29 \Civi\Setup
::log()->info(sprintf('[%s] Handle %s', basename(__FILE__
), 'init'));
31 $cmsPath = \Drupal
::root();
33 // Compute settingsPath.
34 $siteDir = \Civi\Setup\DrupalUtil
::getDrupalSiteDir($cmsPath);
35 $model->settingsPath
= implode(DIRECTORY_SEPARATOR
, [$cmsPath, $siteDir, 'civicrm.settings.php']);
37 if (($loadGenerated = \Drupal\Core\Site\Settings
::get('civicrm_load_generated', NULL)) !== NULL) {
38 $model->loadGenerated
= $loadGenerated;
42 $connectionOptions = \Drupal
::database()->getConnectionOptions();
43 $ssl_params = \Civi\Setup\DrupalUtil
::guessSslParams($connectionOptions);
44 // @todo Does Drupal support unixsocket in config? Set 'server' => 'unix(/path/to/socket.sock)'
45 $model->db
= $model->cmsDb
= array(
46 'server' => \Civi\Setup\DbUtil
::encodeHostPort($connectionOptions['host'], $connectionOptions['port'] ?
: NULL),
47 'username' => $connectionOptions['username'],
48 'password' => $connectionOptions['password'],
49 'database' => $connectionOptions['database'],
50 'ssl_params' => empty($ssl_params) ?
NULL : $ssl_params,
53 // Compute cmsBaseUrl.
54 if (empty($model->cmsBaseUrl
)) {
55 global $base_url, $base_path;
56 $model->cmsBaseUrl
= $base_url . $base_path;
59 // Compute general paths
60 $model->paths
['civicrm.files']['url'] = implode('/', [$model->cmsBaseUrl
, \Drupal\Core\StreamWrapper\PublicStream
::basePath(), 'civicrm']);
61 $model->paths
['civicrm.files']['path'] = implode(DIRECTORY_SEPARATOR
, [_drupal8_civisetup_getPublicFiles(), 'civicrm']);
63 // Compute templateCompileDir.
64 $model->templateCompilePath
= implode(DIRECTORY_SEPARATOR
, [_drupal8_civisetup_getPrivateFiles(), 'civicrm', 'templates_c']);
66 // Compute default locale.
67 $langcode = \Drupal
::languageManager()->getCurrentLanguage()->getId();
68 $model->lang
= \Civi\Setup\LocaleUtil
::pickClosest($langcode, $model->getField('lang', 'options'));
71 function _drupal8_civisetup_getPublicFiles() {
72 $filePublicPath = \Drupal\Core\StreamWrapper\PublicStream
::basePath();
74 if (!$filePublicPath) {
75 throw new \Civi\Setup\Exception\
InitException("Failed to identify public files path");
77 elseif (!CRM_Utils_File
::isAbsolute($filePublicPath)) {
78 $filePublicPath = \Drupal
::root() . DIRECTORY_SEPARATOR
. $filePublicPath;
81 return $filePublicPath;
84 function _drupal8_civisetup_getPrivateFiles() {
85 $filePrivatePath = \Drupal\Core\StreamWrapper\PrivateStream
::basePath();
87 if (!$filePrivatePath) {
88 $filePrivatePath = _drupal8_civisetup_getPublicFiles();
90 elseif ($filePrivatePath && !CRM_Utils_File
::isAbsolute($filePrivatePath)) {
91 $filePrivatePath = \Drupal
::root() . DIRECTORY_SEPARATOR
. $filePrivatePath;
94 return $filePrivatePath;