Few Tips to create a custom module | Drupal 8

Few Tips to create a custom module

Submitted by editor on Wed, 03/29/2017 - 16:58
Question

How to Check module exist ?
How to Get module / Theme install directory ?
How to Get a file in a custom module

 

Check module exist

if (\Drupal::moduleHandler()->moduleExists('my_module')) {
    $message = 'Module exist.';
}
else {
    $message = 'Not exists.';
}

 

Get module / Theme install directory

$path = drupal_get_path('module', 'my_module');

Get a file in a custom module

$path = drupal_get_path('module', 'my_module') . '/my_module.info.yml';

 

Add new comment