function ModuleTestThemeHooks::systemInfoAlter

Implements hook_system_info_alter().

Manipulate module dependencies to test dependency chains.

Attributes

#[Hook('system_info_alter')]

File

core/modules/system/tests/modules/module_test/src/Hook/ModuleTestThemeHooks.php, line 20

Class

ModuleTestThemeHooks
Hook implementations for module_test.

Namespace

Drupal\module_test\Hook

Code

public function systemInfoAlter(&$info, Extension $file, $type) : void {
  if (\Drupal::state()->get('module_test.dependency') == 'missing dependency') {
    if ($file->getName() == 'dblog') {
      // Make dblog module depend on config.
      $info['dependencies'][] = 'config';
    }
    elseif ($file->getName() == 'config') {
      // Make config module depend on a non-existing module.
      $info['dependencies'][] = 'foo';
    }
  }
  elseif (\Drupal::state()->get('module_test.dependency') == 'dependency') {
    if ($file->getName() == 'dblog') {
      // Make dblog module depend on config.
      $info['dependencies'][] = 'config';
    }
    elseif ($file->getName() == 'config') {
      // Make config module depend on help module.
      $info['dependencies'][] = 'help';
    }
    elseif ($file->getName() == 'entity_test') {
      // Make entity test module depend on help module.
      $info['dependencies'][] = 'help';
    }
  }
  elseif (\Drupal::state()->get('module_test.dependency') == 'version dependency') {
    if ($file->getName() == 'dblog') {
      // Make dblog module depend on config.
      $info['dependencies'][] = 'config';
    }
    elseif ($file->getName() == 'config') {
      // Make config module depend on a specific version of help module.
      $info['dependencies'][] = 'help (1.x)';
    }
    elseif ($file->getName() == 'help') {
      // Set help module to a version compatible with the above.
      $info['version'] = '8.x-1.0';
    }
  }
  if ($file->getName() == 'stark' && $type == 'theme') {
    $info['regions']['test_region'] = 'Test region';
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.