protected LibraryDiscoveryParser::parseLibraryInfo($extension, $path)
Parses a given library file and allows modules and themes to alter it.
This method sets the parsed information onto the library property.
Library information is parsed from *.libraries.yml files; see editor.library.yml for an example. Every library must have at least one js or css entry. Each entry starts with a machine name and defines the following elements:
js: path/js/file.js: { attributes: { defer: true } }
If the file has no special attributes, just use an empty object:
js: path/js/file.js: {}
The path of the file is relative to the module or theme directory, unless it starts with a /, in which case it is relative to the Drupal root. If the file path starts with //, it will be treated as a protocol-free, external resource (e.g., //cdn.com/library.js). Full URLs (e.g., http://cdn.com/library.js) as well as URLs that use a valid stream wrapper (e.g., public://path/to/file.js) are also supported.
Each category is itself a key for a sub-list of CSS files to include:
css: component: css/file.css: {}
Just like with JavaScript files, each CSS file is the key of an object that can define specific attributes. The format of the file path is the same as for the JavaScript files.
See https://www.drupal.org/node/2274843#define-library for more information.
string $extension: The name of the extension that registered a library.
string $path: The relative path to the extension.
array An array of parsed library data.
\Drupal\Core\Asset\Exception\InvalidLibraryFileException Thrown when a parser exception got thrown.
protected function parseLibraryInfo($extension, $path) { $libraries = []; $library_file = $path . '/' . $extension . '.libraries.yml'; if (file_exists($this->root . '/' . $library_file)) { try { $libraries = Yaml::decode(file_get_contents($this->root . '/' . $library_file)); } catch (InvalidDataTypeException $e) { // Rethrow a more helpful exception to provide context. throw new InvalidLibraryFileException(sprintf('Invalid library definition in %s: %s', $library_file, $e->getMessage()), 0, $e); } } // Allow modules to add dynamic library definitions. $hook = 'library_info_build'; if ($this->moduleHandler->implementsHook($extension, $hook)) { $libraries = NestedArray::mergeDeep($libraries, $this->moduleHandler->invoke($extension, $hook)); } // Allow modules to alter the module's registered libraries. $this->moduleHandler->alter('library_info', $libraries, $extension); $this->themeManager->alter('library_info', $libraries, $extension); return $libraries; }
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Asset!LibraryDiscoveryParser.php/function/LibraryDiscoveryParser::parseLibraryInfo/8.1.x