In Drupal 8, module's weight is stored into ConfigFactory. Here's how to get or set module weight. Get module weight:
<?php
  $extension_config = \Drupal::configFactory()->getEditable('core.extension');
  $module_weight = $extension_config->get("module.MODULE_NAME");
  echo $module_weight;
?>
Set module weight:
<?php
  module_set_weight('MODULE_NAME', 100);
?>
Tags
Submitted by ychaugule on