5 * Determine default settings for Drupal 7.
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
!== 'Drupal' ||
!function_exists('user_access')) {
19 \Civi\Setup
::log()->info(sprintf('[%s] Handle %s', basename(__FILE__
), 'checkAuthorized'));
20 $e->setAuthorized(user_access('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
!== 'Drupal' ||
!function_exists('user_access')) {
29 \Civi\Setup
::log()->info(sprintf('[%s] Handle %s', basename(__FILE__
), 'init'));
31 // Compute settingsPath.
32 $drupalSystem = new CRM_Utils_System_Drupal();
33 $cmsPath = $drupalSystem->cmsRootPath();
34 $siteDir = \Civi\Setup\DrupalUtil
::getDrupalSiteDir($cmsPath);
35 $model->settingsPath
= implode(DIRECTORY_SEPARATOR
,
36 [$cmsPath, 'sites', $siteDir, 'civicrm.settings.php']);
40 $ssl_params = \Civi\Setup\DrupalUtil
::guessSslParams($databases['default']['default']);
41 $model->db
= $model->cmsDb
= array(
42 'server' => \Civi\Setup\DbUtil
::encodeHostPort($databases['default']['default']['host'], $databases['default']['default']['port'] ?
: NULL),
43 'username' => $databases['default']['default']['username'],
44 'password' => $databases['default']['default']['password'],
45 'database' => $databases['default']['default']['database'],
46 'ssl_params' => empty($ssl_params) ?
NULL : $ssl_params,
49 // Compute cmsBaseUrl.
50 global $base_url, $base_path;
51 $model->cmsBaseUrl
= $base_url . $base_path;
53 // Compute general paths
54 // $model->paths['civicrm.files']['url'] = $filePublicPath;
55 $model->paths
['civicrm.files']['path'] = implode(DIRECTORY_SEPARATOR
,
56 [_drupal_civisetup_getPublicFiles(), 'civicrm']);
58 // Compute templateCompileDir.
59 $model->templateCompilePath
= implode(DIRECTORY_SEPARATOR
,
60 [_drupal_civisetup_getPrivateFiles(), 'civicrm', 'templates_c']);
62 // Compute default locale.
64 $model->lang
= \Civi\Setup\LocaleUtil
::pickClosest($language->langcode ??
NULL, $model->getField('lang', 'options'));
67 function _drupal_civisetup_getPublicFiles() {
68 $filePublicPath = variable_get('file_public_path', conf_path() . '/files');
70 if (!CRM_Utils_File
::isAbsolute($filePublicPath)) {
71 $drupalSystem = new CRM_Utils_System_Drupal();
72 $cmsPath = $drupalSystem->cmsRootPath();
73 $filePublicPath = $cmsPath . DIRECTORY_SEPARATOR
. $filePublicPath;
76 return $filePublicPath;
79 function _drupal_civisetup_getPrivateFiles() {
80 $filePrivatePath = variable_get('file_private_path', '');
82 if (!$filePrivatePath) {
83 $filePrivatePath = _drupal_civisetup_getPublicFiles();
85 elseif ($filePrivatePath && !CRM_Utils_File
::isAbsolute($filePrivatePath)) {
86 $drupalSystem = new CRM_Utils_System_Drupal();
87 $cmsPath = $drupalSystem->cmsRootPath();
89 $filePrivatePath = $cmsPath . DIRECTORY_SEPARATOR
. $filePrivatePath;
92 return $filePrivatePath;