View source
<?php
namespace Drupal\service_container\Extension;
use Drupal\Core\Extension\Extension;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\service_container\Legacy\Drupal7;
class ModuleHandler implements ModuleHandlerInterface {
protected $drupal7;
protected $root;
public function __construct($root, Drupal7 $drupal7) {
$this->root = $root;
$this->drupal7 = $drupal7;
}
public function load($name) {
return $this->drupal7
->drupal_load('module', $name);
}
public function loadAll() {
$this->drupal7
->module_load_all();
}
public function reload() {
$this->drupal7
->module_load_all();
}
public function isLoaded() {
return $this->drupal7
->module_load_all();
}
public function getModuleList() {
$module_list = array();
foreach ($this->drupal7
->module_list() as $module) {
$module_list[$module] = $this
->getModule($module);
}
return $module_list;
}
public function getModule($name) {
if (!$this->drupal7
->module_exists($name)) {
throw new \InvalidArgumentException(sprintf('The module %s does not exist.', $name));
}
$filename = $this->drupal7
->drupal_get_filename('module', $name);
return new Extension($this->root, 'module', $filename, $name . '.info');
}
public function setModuleList(array $module_list = array()) {
foreach ($module_list as $module_name => $filename) {
$module_list[$module_name] = array(
'filename' => $filename,
);
}
$this->drupal7
->module_list(FALSE, FALSE, FALSE, $module_list);
}
public function addModule($name, $path) {
throw new \BadMethodCallException('ModuleHandler::addModule is not implemented.');
}
public function addProfile($name, $path) {
throw new \BadMethodCallException('ModuleHandler::addProfile is not implemented.');
}
public function buildModuleDependencies(array $modules) {
}
public function moduleExists($module) {
return $this->drupal7
->module_exists($module);
}
public function loadAllIncludes($type, $name = NULL) {
$this->drupal7
->module_load_all_includes($type, $name);
}
public function loadInclude($module, $type, $name = NULL) {
$this->drupal7
->module_load_include($type, $module, $name);
}
public function getHookInfo() {
return $this->drupal7
->module_hook_info();
}
public function getImplementations($hook) {
return $this->drupal7
->module_implements($hook);
}
public function writeCache() {
$this->drupal7
->module_implements_write_cache();
}
public function resetImplementations() {
$this->drupal7
->drupal_static_reset('module_implements');
}
public function implementsHook($module, $hook) {
$implementations = $this->drupal7
->module_implements($hook);
return in_array($module, $implementations);
}
public function invoke($module, $hook, array $args = array()) {
return $this->drupal7
->module_invoke($module, $hook, $args);
}
public function invokeAll($hook, array $args = array()) {
return $this->drupal7
->module_invoke_all($hook, $args);
}
public function alter($type, &$data, &$context1 = NULL, &$context2 = NULL) {
$this->drupal7
->drupal_alter($type, $data, $context1, $context2);
}
public function getModuleDirectories() {
$dirs = array();
foreach ($this
->getModuleList() as $name => $module) {
$dirs[$name] = $this->root . '/' . $module
->getPath();
}
return $dirs;
}
public function getName($module) {
$module_data = $this->drupal7
->system_rebuild_module_data();
return $module_data[$module]->info['name'];
}
}