varbase_email.install in Varbase Email 8.6
Same filename and directory in other branches
Install, update and uninstall functions for the Varbase email module.
File
varbase_email.installView source
<?php
/**
* @file
* Install, update and uninstall functions for the Varbase email module.
*/
use Symfony\Component\Yaml\Yaml;
use Drupal\Core\Config\InstallStorage;
use Drupal\Core\Config\StorageInterface;
use Drupal\Core\Config\FileStorage;
/**
* Implements hook_install().
*/
function varbase_email_install() {
$module_name = preg_replace('/_install$/', '', __FUNCTION__);
$module_path = Drupal::service('module_handler')
->getModule($module_name)
->getPath();
// Install optional configs.
$optional_install_path = $module_path . '/' . InstallStorage::CONFIG_OPTIONAL_DIRECTORY;
if (is_dir($optional_install_path)) {
$config_installer = \Drupal::service('config.installer');
$config_installer
->installDefaultConfig('module', $module_name);
// Install any optional config the module provides.
$storage = new FileStorage($optional_install_path, StorageInterface::DEFAULT_COLLECTION);
$config_installer
->installOptionalConfig($storage, '');
// Have the .settings.yml configs into the active config.
$settings_config_files = \Drupal::service('file_system')
->scanDirectory($optional_install_path, '/^.*\\.(yml)$/i');
if (isset($settings_config_files) && is_array($settings_config_files)) {
foreach ($settings_config_files as $settings_config_file) {
$settings_config_file_content = file_get_contents(DRUPAL_ROOT . '/' . $settings_config_file->uri);
$settings_config_file_data = (array) Yaml::parse($settings_config_file_content);
$config_factory = \Drupal::configFactory()
->getEditable($settings_config_file->name);
$config_factory
->setData($settings_config_file_data)
->save(TRUE);
}
}
}
// ------------------------------------------------------------------------.
}
Functions
Name | Description |
---|---|
varbase_email_install | Implements hook_install(). |