You are here

function thunder_modules_installed in Thunder 8.4

Same name and namespace in other branches
  1. 8.5 thunder.profile \thunder_modules_installed()
  2. 8.2 thunder.profile \thunder_modules_installed()
  3. 8.3 thunder.profile \thunder_modules_installed()
  4. 6.2.x thunder.profile \thunder_modules_installed()
  5. 6.0.x thunder.profile \thunder_modules_installed()
  6. 6.1.x thunder.profile \thunder_modules_installed()

Implements hook_modules_installed().

File

./thunder.profile, line 228
Enables modules and site configuration for a thunder site installation.

Code

function thunder_modules_installed($modules) {
  if (_thunder_is_enabling_module() && _thunder_check_triggering_modules($modules, [
    'content_moderation',
    'config_update',
  ])) {
    if (!Role::load('restricted_editor')) {

      /** @var Drupal\config_update\ConfigRevertInterface $configReverter */
      $configReverter = \Drupal::service('config_update.config_update');
      $configReverter
        ->import('user_role', 'restricted_editor');
    }

    // Granting permissions only for "editor" and "seo" user roles.
    $roles = Role::loadMultiple([
      'editor',
      'seo',
    ]);
    foreach ($roles as $role) {
      try {
        $role
          ->grantPermission('use editorial transition create_new_draft');
        $role
          ->grantPermission('use editorial transition publish');
        $role
          ->grantPermission('use editorial transition unpublish');
        $role
          ->grantPermission('use editorial transition unpublished_draft');
        $role
          ->grantPermission('use editorial transition unpublished_published');
        $role
          ->grantPermission('view any unpublished content');
        $role
          ->grantPermission('view latest version');
        $role
          ->save();
      } catch (EntityStorageException $storageException) {
      }
    }
  }
  if (_thunder_is_enabling_module() && _thunder_check_triggering_modules($modules, [
    'content_moderation',
    'scheduler',
  ])) {
    \Drupal::service('module_installer')
      ->install([
      'scheduler_content_moderation_integration',
    ]);
  }

  // When enabling password policy, enabled required sub modules.
  if (_thunder_is_enabling_module() && _thunder_check_triggering_modules($modules, [
    'password_policy',
  ])) {
    \Drupal::service('module_installer')
      ->install([
      'password_policy_length',
    ]);
    \Drupal::service('module_installer')
      ->install([
      'password_policy_history',
    ]);
    \Drupal::service('module_installer')
      ->install([
      'password_policy_character_types',
    ]);
    \Drupal::service('messenger')
      ->addStatus(t('The Password Character Length, Password Policy History and Password Character Types modules have been additionally enabled, they are required by the default policy configuration.'));
  }

  // Move fields into form display.
  if (_thunder_check_triggering_modules($modules, [
    'ivw_integration',
  ])) {
    $fieldWidget = 'ivw_integration_widget';

    // Attach field if channel vocabulary and article node type is
    // present in the distribution.
    try {
      \Drupal::service('entity_display.repository')
        ->getFormDisplay('node', 'article', 'default')
        ->setComponent('field_ivw', [
        'type' => $fieldWidget,
      ])
        ->save();
    } catch (Exception $e) {
      \Drupal::logger('thunder')
        ->info(t('Could not add ivw field to article node: "@message"', [
        '@message' => $e
          ->getMessage(),
      ]));
    }
    try {
      \Drupal::service('entity_display.repository')
        ->getFormDisplay('taxonomy_term', 'channel', 'default')
        ->setComponent('field_ivw', [
        'type' => $fieldWidget,
      ])
        ->save();
    } catch (Exception $e) {
      \Drupal::logger('thunder')
        ->info(t('Could not add ivw field to channel taxonomy: "@message"', [
        '@message' => $e
          ->getMessage(),
      ]));
    }
  }

  // When enabling content_translation, grant permissions to Thunder user roles.
  if (_thunder_check_triggering_modules($modules, [
    'content_translation',
  ])) {

    /** @var \Drupal\user\Entity\Role[] $roles */
    $roles = Role::loadMultiple([
      'editor',
      'seo',
      'restricted_editor',
    ]);
    foreach ($roles as $role) {
      try {
        $role
          ->grantPermission('create content translations');
        $role
          ->grantPermission('update content translations');
        $role
          ->grantPermission('translate any entity');
        if (in_array($role
          ->id(), [
          'editor',
          'seo',
        ])) {
          $role
            ->grantPermission('delete content translations');
        }
        $role
          ->save();
      } catch (EntityStorageException $storageException) {
      }
    }
  }
}