-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Turned PdbBlockDervier's component discovery code into a separate ser…
…vice.
- Loading branch information
Phéna Proxima
committed
Apr 28, 2016
1 parent
b265b06
commit 04b6a6f
Showing
4 changed files
with
106 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
services: | ||
pdb.component_discovery: | ||
class: '\Drupal\pdb\ComponentDiscovery' | ||
arguments: | ||
- '@app.root' | ||
- '@module_handler' | ||
- '@info_parser' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Contains \Drupal\pdb\ComponentDiscovery. | ||
*/ | ||
|
||
namespace Drupal\pdb; | ||
|
||
use Drupal\Core\Extension\ExtensionDiscovery; | ||
use Drupal\Core\Extension\InfoParserInterface; | ||
use Drupal\Core\Extension\ModuleHandlerInterface; | ||
|
||
class ComponentDiscovery extends ExtensionDiscovery implements ComponentDiscoveryInterface { | ||
|
||
/** | ||
* The module handler. | ||
* | ||
* @var \Drupal\Core\Extension\ModuleHandlerInterface | ||
*/ | ||
protected $moduleHandler; | ||
|
||
/** | ||
* The info parser. | ||
* | ||
* @var \Drupal\Core\Extension\InfoParserInterface | ||
*/ | ||
protected $infoParser; | ||
|
||
/** | ||
* ComponentDiscovery constructor. | ||
* | ||
* @param string $root | ||
* The root directory of the Drupal installation. | ||
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler | ||
* The module handler. | ||
* @param \Drupal\Core\Extension\InfoParserInterface $info_parser | ||
* The info parser. | ||
*/ | ||
public function __construct($root, ModuleHandlerInterface $module_handler, InfoParserInterface $info_parser) { | ||
parent::__construct($root); | ||
$this->moduleHandler = $module_handler; | ||
$this->infoParser = $info_parser; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getComponents() { | ||
// Find components. | ||
$components = $this->scan('pdb'); | ||
|
||
// Set defaults for module info. | ||
$defaults = array( | ||
'dependencies' => array(), | ||
'description' => '', | ||
'package' => 'Other', | ||
'version' => NULL, | ||
); | ||
|
||
// Read info files for each module. | ||
foreach ($components as $key => $component) { | ||
// Look for the info file. | ||
$component->info = $this->infoParser->parse($component->getPathname()); | ||
$component->info['path'] = $component->origin . '/' . $component->subpath; | ||
|
||
// Merge in defaults and save. | ||
$components[$key]->info = $component->info + $defaults; | ||
} | ||
$this->moduleHandler->alter('component_info', $components); | ||
|
||
return $components; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Contains \Drupal\pdb\ComponentDiscoveryInterface. | ||
*/ | ||
|
||
namespace Drupal\pdb; | ||
|
||
interface ComponentDiscoveryInterface { | ||
|
||
public function getComponents(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters