You are here

function lightning_workflow_modules_installed in Lightning Workflow 8

Same name and namespace in other branches
  1. 8.3 lightning_workflow.module \lightning_workflow_modules_installed()
  2. 8.2 lightning_workflow.module \lightning_workflow_modules_installed()

Implements hook_modules_installed().

1 call to lightning_workflow_modules_installed()
lightning_workflow_install in ./lightning_workflow.install
Implements hook_install().

File

./lightning_workflow.module, line 148
Provides workflow enhancements for Drupal.

Code

function lightning_workflow_modules_installed(array $modules) {

  // Don't do anything during config sync.
  if (\Drupal::isConfigSyncing()) {
    return;
  }
  if (in_array('lightning_roles', $modules, TRUE)) {
    \Drupal::service('lightning.content_roles')
      ->grantPermissions('creator', [
      'use editorial transition create_new_draft',
      'use editorial transition review',
      'view any unpublished content',
      'view latest version',
    ])
      ->grantPermissions('reviewer', [
      'use editorial transition publish',
      'use editorial transition review',
      'use editorial transition archive',
      'view any unpublished content',
      'view latest version',
    ]);
  }
  if (in_array('lightning_dev', $modules, TRUE)) {

    /** @var \Drupal\Core\Extension\ModuleInstallerInterface $module_installer */
    $module_installer = \Drupal::service('module_installer');

    // Lightning Workflow optionally integrates with Diff, and for testing
    // purposes we'd like to enable that integration. In order to test with
    // meaningful responsibility-based roles, we also enable Lightning Roles.
    $module_installer
      ->install([
      'diff',
      'lightning_roles',
    ]);

    // BigPipe breaks a couple of non-JS tests which expect to find local task
    // links, but receive BigPipe placeholders instead. This is a bit of a
    // sledgehammer approach, but until it's possible to disable a module during
    // a single test, it's the best we can do.
    $module_installer
      ->uninstall([
      'big_pipe',
    ]);

    // Add moderation to the page content type.

    /** @var NodeTypeInterface $node_type */
    $node_type = entity_load('node_type', 'page');
    $node_type
      ->setThirdPartySetting('lightning_workflow', 'workflow', 'editorial');
    lightning_workflow_node_type_insert($node_type);

    // Allow the content view to filter by moderation state.
    $view = entity_load('view', 'content')
      ->enforceIsNew();
    lightning_workflow_view_presave($view);
    $view
      ->enforceIsNew(FALSE)
      ->save();
  }
}