You are here

protected function LocalRemoteAssetTrait::getPathPrefix in Libraries API 8.3

Gets the prefix to prepend to file paths.

For local libraries this is the library path, for remote libraries this is the remote URL.

Return value

string The path prefix.

File

src/ExternalLibrary/Asset/LocalRemoteAssetTrait.php, line 41

Class

LocalRemoteAssetTrait
A trait for asset libraries that serve local and remote files.

Namespace

Drupal\libraries\ExternalLibrary\Asset

Code

protected function getPathPrefix() {

  /** @var \Drupal\libraries\ExternalLibrary\Local\LocalLibraryInterface|\Drupal\libraries\ExternalLibrary\Remote\RemoteLibraryInterface $this */
  if ($this
    ->isInstalled()) {

    // LocalLibraryInterface::getLocalPath() returns the path relative to the
    // app root. In order for the core core asset system to register the path
    // as relative to the app root, a leading slash is required.

    /** @see \Drupal\Core\Asset\LibraryDiscoveryParser::buildByExtension() */
    return '/' . $this
      ->getLocalPath();
  }
  elseif ($this
    ->hasRemoteUrl()) {
    return $this
      ->getRemoteUrl();
  }
  else {

    // @todo Throw an exception.
  }
}