Merge pull request #17235 from colemanw/apiLog
[civicrm-core.git] / setup / plugins / installDatabase / FlushDrupal8.civi-setup.php
CommitLineData
4bcd4c62
TO
1<?php
2/**
3 * @file
4 *
5 * Finalize any extra CMS changes in Drupal.
6 */
7
8if (!defined('CIVI_SETUP')) {
9 exit("Installation plugins must only be loaded by the installer.\n");
10}
11
12\Civi\Setup::dispatcher()
13 ->addListener('civi.setup.installDatabase', function (\Civi\Setup\Event\InstallDatabaseEvent $e) {
14 if ($e->getModel()->cms !== 'Drupal8') {
15 return;
16 }
17 \Civi\Setup::log()->info(sprintf('[%s] Flush CMS metadata', basename(__FILE__)));
18
19 system_rebuild_module_data();
20 \Drupal::service('module_installer')->install(['civicrm', 'civicrmtheme']);
21 drupal_flush_all_caches();
22 civicrm_install_set_drupal8_perms();
23
24 }, \Civi\Setup::PRIORITY_LATE - 50);
25
26function civicrm_install_set_drupal8_perms() {
27 $perms = array(
28 'access all custom data',
29 'access uploaded files',
30 'make online contributions',
31 'profile create',
32 'profile edit',
33 'profile view',
34 'register for events',
35 'view event info',
36 'view event participants',
37 'access CiviMail subscribe/unsubscribe pages',
38 );
39
40 // Adding a permission that has not yet been assigned to a module by
41 // a hook_permission implementation results in a database error.
42 // CRM-9042
43
44 /** @var \Drupal\user\PermissionHandlerInterface $permissionHandler */
45 $permissionHandler = \Drupal::service('user.permissions');
46
47 $allPerms = array_keys($permissionHandler->getPermissions());
48 foreach (array_diff($perms, $allPerms) as $perm) {
49 \Drupal::logger('my_module')->error('Cannot grant the %perm permission because it does not yet exist.', [
50 '%perm' => $perm,
51 ]);
52 }
53 $perms = array_intersect($perms, $allPerms);
54 user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, $perms);
55 user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, $perms);
56}