Drupal 8  8.0.2
LibraryDiscoveryParser Class Reference
Inheritance diagram for LibraryDiscoveryParser:

Public Member Functions

 __construct ($root, ModuleHandlerInterface $module_handler, ThemeManagerInterface $theme_manager)
 
 buildByExtension ($extension)
 

Protected Member Functions

 parseLibraryInfo ($extension, $path)
 
 applyLibrariesOverride ($libraries, $extension)
 
 drupalGetPath ($type, $name)
 
 fileValidUri ($source)
 
 isValidUri ($string)
 
 setOverrideValue (array &$library, array $sub_key, array $overrides, $theme_path)
 
 resolveThemeAssetPath ($theme_path, $overriding_asset)
 

Protected Attributes

 $moduleHandler
 
 $themeManager
 
 $root
 

Detailed Description

Parses library files to get extension data.

Constructor & Destructor Documentation

__construct (   $root,
ModuleHandlerInterface  $module_handler,
ThemeManagerInterface  $theme_manager 
)

Constructs a new LibraryDiscoveryParser instance.

Parameters
string$rootThe app root.
\Drupal\Core\Extension\ModuleHandlerInterface$module_handlerThe module handler.
\Drupal\Core\Theme\ThemeManagerInterface$theme_managerThe theme manager.

References Drupal\moduleHandler(), and Drupal\root().

Here is the call graph for this function:

Member Function Documentation

applyLibrariesOverride (   $libraries,
  $extension 
)
protected

Apply libraries overrides specified for the current active theme.

Parameters
array$librariesThe libraries definitions.
string$extensionThe extension in which these libraries are defined.
Returns
array The modified libraries definitions.

References LibraryDiscoveryParser\setOverrideValue().

Referenced by LibraryDiscoveryParser\buildByExtension().

Here is the call graph for this function:

Here is the caller graph for this function:

buildByExtension (   $extension)

Parses and builds up all the libraries information of an extension.

Parameters
string$extensionThe name of the extension that registered a library.
Returns
array All library definitions of the passed extension.
Exceptions
\Drupal\Core\Asset\Exception\IncompleteLibraryDefinitionExceptionThrown when a library has no js/css/setting.
\UnexpectedValueExceptionThrown when a js file defines a positive weight.

References LibraryDiscoveryParser\applyLibrariesOverride(), LibraryDiscoveryParser\drupalGetPath(), LibraryDiscoveryParser\fileValidUri(), LibraryDiscoveryParser\isValidUri(), Drupal\moduleHandler(), LibraryDiscoveryParser\parseLibraryInfo(), and Drupal\VERSION.

Here is the call graph for this function:

drupalGetPath (   $type,
  $name 
)
protected

Wraps drupal_get_path().

Referenced by LibraryDiscoveryParser\buildByExtension().

Here is the caller graph for this function:

fileValidUri (   $source)
protected

Wraps file_valid_uri().

References file_valid_uri().

Referenced by LibraryDiscoveryParser\buildByExtension().

Here is the call graph for this function:

Here is the caller graph for this function:

isValidUri (   $string)
protected

Determines if the supplied string is a valid URI.

Referenced by LibraryDiscoveryParser\buildByExtension(), and LibraryDiscoveryParser\resolveThemeAssetPath().

Here is the caller graph for this function:

parseLibraryInfo (   $extension,
  $path 
)
protected

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: A list of JavaScript files to include. Each file is keyed by the file path. An item can have several attributes (like HTML attributes). For example:
    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.
  • css: A list of categories for which the library provides CSS files. The available categories are:
    • base
    • layout
    • component
    • state
    • theme 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.
  • dependencies: A list of libraries this library depends on.
  • version: The library version. The string "VERSION" can be used to mean the current Drupal core version.
  • header: By default, JavaScript files are included in the footer. If the script must be included in the header (along with all its dependencies), set this to true. Defaults to false.
  • minified: If the file is already minified, set this to true to avoid minifying it again. Defaults to false.
  • remote: If the library is a third-party script, this provides the repository URL for reference.
  • license: If the remote property is set, the license information is required. It has 3 properties:
    • name: The human-readable name of the license.
    • url: The URL of the license file/information for the version of the library used.
    • gpl-compatible: A Boolean for whether this library is GPL compatible.

See https://www.drupal.org/node/2274843#define-library for more information.

Parameters
string$extensionThe name of the extension that registered a library.
string$pathThe relative path to the extension.
Returns
array An array of parsed library data.
Exceptions
\Drupal\Core\Asset\Exception\InvalidLibraryFileExceptionThrown when a parser exception got thrown.

References Yaml\decode(), NestedArray\mergeDeep(), Drupal\moduleHandler(), and Drupal\root().

Referenced by LibraryDiscoveryParser\buildByExtension().

Here is the call graph for this function:

Here is the caller graph for this function:

resolveThemeAssetPath (   $theme_path,
  $overriding_asset 
)
protected

Ensures that a full path is returned for an overriding theme asset.

Parameters
string$theme_pathThe theme or base theme.
string$overriding_assetThe overriding library asset.
Returns
string A fully resolved theme asset path relative to the Drupal directory.

References LibraryDiscoveryParser\isValidUri().

Referenced by LibraryDiscoveryParser\setOverrideValue().

Here is the call graph for this function:

Here is the caller graph for this function:

setOverrideValue ( array &  $library,
array  $sub_key,
array  $overrides,
  $theme_path 
)
protected

Overrides the specified library asset.

Parameters
array$libraryThe containing library definition.
array$sub_keyAn array containing the sub-keys specifying the library asset, e.g.
['js']
or
['css', 'component']
array$overridesSpecifies the overrides, this is an array where the key is the asset to be overridden while the value is overriding asset.

References NestedArray\getValue(), LibraryDiscoveryParser\resolveThemeAssetPath(), NestedArray\setValue(), and NestedArray\unsetValue().

Referenced by LibraryDiscoveryParser\applyLibrariesOverride().

Here is the call graph for this function:

Here is the caller graph for this function:


The documentation for this class was generated from the following file: