Skip to content
Snippets Groups Projects
Commit a1deca01 authored by Mark Miller's avatar Mark Miller Committed by Mark Miller
Browse files

Issue #3179730 by segovia94: Use a custom info parser method so that the...

Issue #3179730 by segovia94: Use a custom info parser method so that the info.yml files won't need keys required by modules
parent 095aab81
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,5 @@ services:
arguments:
- '%app.root%'
- '@event_dispatcher'
- '@info_parser'
- '@module_handler'
public: true
......@@ -6,11 +6,13 @@ use Drupal\pdb\Discovery\PdbRecursiveExtensionFilterIterator;
use Drupal\pdb\Event\PdbDiscoveryEvent;
use Drupal\Core\Extension\ExtensionDiscovery;
use Drupal\Core\Extension\InfoParserInterface;
use Drupal\Core\Extension\InfoParserException;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Extension\Extension;
use Drupal\Core\Site\Settings;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Drupal\Component\Serialization\Exception\InvalidDataTypeException;
use Drupal\Core\Serialization\Yaml;
/**
* Discovery service for front-end components provided by modules and themes.
......@@ -27,13 +29,6 @@ class ComponentDiscovery extends ExtensionDiscovery implements ComponentDiscover
*/
protected $eventDispatcher;
/**
* The info parser.
*
* @var \Drupal\Core\Extension\InfoParserInterface
*/
protected $infoParser;
/**
* The module handler.
*
......@@ -55,15 +50,12 @@ class ComponentDiscovery extends ExtensionDiscovery implements ComponentDiscover
* The root directory of the Drupal installation.
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher
* The event dispatcher.
* @param \Drupal\Core\Extension\InfoParserInterface $info_parser
* The info parser.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
*/
public function __construct($root, EventDispatcherInterface $event_dispatcher, InfoParserInterface $info_parser, ModuleHandlerInterface $module_handler) {
public function __construct($root, EventDispatcherInterface $event_dispatcher, ModuleHandlerInterface $module_handler) {
parent::__construct($root);
$this->eventDispatcher = $event_dispatcher;
$this->infoParser = $info_parser;
$this->moduleHandler = $module_handler;
}
......@@ -84,7 +76,7 @@ class ComponentDiscovery extends ExtensionDiscovery implements ComponentDiscover
// 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 = $this->parse($component->getPathname());
// Merge in defaults and save.
$components[$key]->info = $component->info + $defaults;
}
......@@ -264,4 +256,28 @@ class ComponentDiscovery extends ExtensionDiscovery implements ComponentDiscover
return $files;
}
/**
* Parse the *.info.yml file.
*
* @param string $filename
* The name of the info file.
*
* @return array
* A list of the PDB components.
*/
protected function parse($filename) {
if (!file_exists($filename)) {
$parsed_info = [];
}
else {
try {
$parsed_info = Yaml::decode(file_get_contents($filename));
}
catch (InvalidDataTypeException $e) {
throw new InfoParserException("Unable to parse $filename " . $e->getMessage());
}
}
return $parsed_info;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment