Tuesday 1 December 2015

Check wether the module exist or not in drupal 8


\Drupal::moduleHandler()->moduleExists("module_name");

How to set/get weight for modules and how to enable module programatically in druapl 8


In Druapl 7 the "system" table will have all the module enable and disable status. In druapl 8
 
Description: 
If you were running any queries against the {system} table, these won't work any more. For example:
Drupal 7:
<?php
  // Enable the admin theme.
  db_update('system')
    ->fields(array('status' => 1))
    ->condition('type', 'theme')
    ->condition('name', 'seven')
    ->execute();
?>

Drupal 8:
<?php
  theme_enable(array('seven'));
?>
 
Enable Module: 
 module_enable(array($module), FALSE); 

 module_enable($module_list, $enable_dependencies = TRUE) 

Reff: http://www.drupalcontrib.org/api/drupal/drupal!core!includes!module.inc/function/module_enable/8

Setting module weights:
Drupal 7:
<?php
  // Set a module's weight.
  db_update('system')
    ->fields(array('weight' => $weight))
    ->condition('name', $mymodule)
    ->execute();
?>
Drupal 8:
<?php
  module_set_weight($mymodule, $weight);
?>
To set a module's weight relative to another, a module_get_weight function is planned.

Source : https://www.drupal.org/node/1813642