3 namespace Drupal\Core\Extension;
5 use Drupal\Component\Serialization\Exception\InvalidDataTypeException;
6 use Drupal\Core\Serialization\Yaml;
9 * Parses dynamic .info.yml files that might change during the page request.
11 class InfoParserDynamic implements InfoParserInterface {
16 public function parse($filename) {
17 if (!file_exists($filename)) {
22 $parsed_info = Yaml::decode(file_get_contents($filename));
24 catch (InvalidDataTypeException $e) {
25 throw new InfoParserException("Unable to parse $filename " . $e->getMessage());
27 $missing_keys = array_diff($this->getRequiredKeys(), array_keys($parsed_info));
28 if (!empty($missing_keys)) {
29 throw new InfoParserException('Missing required keys (' . implode(', ', $missing_keys) . ') in ' . $filename);
31 if (isset($parsed_info['version']) && $parsed_info['version'] === 'VERSION') {
32 $parsed_info['version'] = \Drupal::VERSION;
34 // Special backwards compatible handling profiles and their 'dependencies'
36 if ($parsed_info['type'] === 'profile' && isset($parsed_info['dependencies']) && !array_key_exists('install', $parsed_info)) {
37 // Only trigger the deprecation message if we are actually using the
38 // profile with the missing 'install' key. This avoids triggering the
39 // deprecation when scanning all the available install profiles.
40 global $install_state;
41 if (isset($install_state['parameters']['profile'])) {
42 $pattern = '@' . preg_quote(DIRECTORY_SEPARATOR . $install_state['parameters']['profile'] . '.info.yml') . '$@';
43 if (preg_match($pattern, $filename)) {
44 @trigger_error("The install profile $filename only implements a 'dependencies' key. As of Drupal 8.6.0 profile's support a new 'install' key for modules that should be installed but not depended on. See https://www.drupal.org/node/2952947.", E_USER_DEPRECATED);
47 // Move dependencies to install so that if a profile has both
48 // dependencies and install then dependencies are real.
49 $parsed_info['install'] = $parsed_info['dependencies'];
50 $parsed_info['dependencies'] = [];
57 * Returns an array of keys required to exist in .info.yml file.
60 * An array of required keys.
62 protected function getRequiredKeys() {
63 return ['type', 'core', 'name'];