Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions src/ComponentDiscovery.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Drupal\pdb;

use Drupal\Core\Extension\Extension;
use Drupal\Core\Extension\ExtensionDiscovery;
use Drupal\Core\Extension\InfoParserInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
Expand Down Expand Up @@ -61,14 +62,40 @@ public function getComponents() {

// Read info files for each module.
foreach ($components as $key => $component) {
// Look for the info file.
$component->info = $this->infoParser->parse($component->getPathname());
// Merge in defaults and save.
$components[$key]->info = $component->info + $defaults;
if ($this->moduleIsEnabled($component)) {
// Look for the info file.
$component->info = $this->infoParser->parse($component->getPathname());
// Merge in defaults and save.
$components[$key]->info = $component->info + $defaults;
}
else {
// Don't show components from disabled modules.
unset($components[$key]);
}
}
$this->moduleHandler->alter('component_info', $components);

return $components;
}

/**
* Check if component's module is enabled.
*
* @param \Drupal\Core\Extension\Extension $component
* Component object.
*
* @return bool|null
* TRUE if module is enabled.
*/
protected function moduleIsEnabled(Extension $component) {
/** @var \Drupal\Core\Extension\Extension $module */
// Load enabled modules and iterate.
foreach ($enabled_modules = $this->moduleHandler->getModuleList() as $module) {
// Match component and module using their paths.
if (strpos($component->getPath(), $module->getPath() . '/components/') !== FALSE) {
return TRUE;
}
}
}

}