Issue #2245449 by lostkangaroo, chx, Xano: Added a ModuleHandler::getModule().
parent
43324d1752
commit
c1ca622460
|
@ -148,6 +148,16 @@ class ModuleHandler implements ModuleHandlerInterface {
|
||||||
return $this->moduleList;
|
return $this->moduleList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getModule($name) {
|
||||||
|
if (isset($this->moduleList[$name])) {
|
||||||
|
return $this->moduleList[$name];
|
||||||
|
}
|
||||||
|
throw new \InvalidArgumentException(sprintf('The module %s does not exist.', $name));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -57,6 +57,20 @@ interface ModuleHandlerInterface {
|
||||||
*/
|
*/
|
||||||
public function getModuleList();
|
public function getModuleList();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a module extension object from the currently active modules list.
|
||||||
|
*
|
||||||
|
* @param string $name
|
||||||
|
* The name of the module to return.
|
||||||
|
*
|
||||||
|
* @return \Drupal\Core\Extension\Extension
|
||||||
|
* An extension object.
|
||||||
|
*
|
||||||
|
* @throws \InvalidArgumentException
|
||||||
|
* Thrown when the requested module does not exist.
|
||||||
|
*/
|
||||||
|
public function getModule($name);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets an explicit list of currently active modules.
|
* Sets an explicit list of currently active modules.
|
||||||
*
|
*
|
||||||
|
|
|
@ -49,6 +49,8 @@ class ModuleHandlerTest extends UnitTestCase {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
|
*
|
||||||
|
* @covers ::__construct
|
||||||
*/
|
*/
|
||||||
protected function setUp() {
|
protected function setUp() {
|
||||||
$this->cacheBackend = $this->getMock('Drupal\Core\Cache\CacheBackendInterface');
|
$this->cacheBackend = $this->getMock('Drupal\Core\Cache\CacheBackendInterface');
|
||||||
|
@ -151,6 +153,24 @@ class ModuleHandlerTest extends UnitTestCase {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Confirm we get back a module from the module list
|
||||||
|
*
|
||||||
|
* @covers ::getModule
|
||||||
|
*/
|
||||||
|
public function testGetModuleWithExistingModule() {
|
||||||
|
$this->assertEquals($this->moduleHandler->getModule('module_handler_test'), new Extension('module', 'core/tests/Drupal/Tests/Core/Extension/modules/module_handler_test/module_handler_test.info.yml', 'module_handler_test.module'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::getModule
|
||||||
|
*
|
||||||
|
* @expectedException \InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function testGetModuleWithNonExistingModule() {
|
||||||
|
$this->moduleHandler->getModule('claire_alice_watch_my_little_pony_module_that_does_not_exist');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ensure setting the module list replaces the module list and resets internal structures.
|
* Ensure setting the module list replaces the module list and resets internal structures.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue