Chris@0: getTarget()); Chris@0: return static::baseUrl() . '/' . UrlHelper::encodePath($path); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Finds and returns the base URL for public://. Chris@0: * Chris@0: * Defaults to the current site's base URL plus directory path. Chris@0: * Chris@0: * Note that this static method is used by \Drupal\system\Form\FileSystemForm Chris@0: * so you should alter that form or substitute a different form if you change Chris@0: * the class providing the stream_wrapper.public service. Chris@0: * Chris@0: * @return string Chris@0: * The external base URL for public:// Chris@0: */ Chris@0: public static function baseUrl() { Chris@0: $settings_base_url = Settings::get('file_public_base_url', ''); Chris@0: if ($settings_base_url) { Chris@0: return (string) $settings_base_url; Chris@0: } Chris@0: else { Chris@0: return $GLOBALS['base_url'] . '/' . static::basePath(); Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the base path for public://. Chris@0: * Chris@0: * If we have a setting for the public:// scheme's path, we use that. Chris@0: * Otherwise we build a reasonable default based on the site.path service if Chris@0: * it's available, or a default behavior based on the request. Chris@0: * Chris@0: * Note that this static method is used by \Drupal\system\Form\FileSystemForm Chris@0: * so you should alter that form or substitute a different form if you change Chris@0: * the class providing the stream_wrapper.public service. Chris@0: * Chris@0: * The site path is injectable from the site.path service: Chris@0: * @code Chris@0: * $base_path = PublicStream::basePath(\Drupal::service('site.path')); Chris@0: * @endcode Chris@0: * Chris@0: * @param \SplString $site_path Chris@0: * (optional) The site.path service parameter, which is typically the path Chris@0: * to sites/ in a Drupal installation. This allows you to inject the site Chris@0: * path using services from the caller. If omitted, this method will use the Chris@0: * global service container or the kernel's default behavior to determine Chris@0: * the site path. Chris@0: * Chris@0: * @return string Chris@0: * The base path for public:// typically sites/default/files. Chris@0: */ Chris@0: public static function basePath(\SplString $site_path = NULL) { Chris@0: if ($site_path === NULL) { Chris@0: // Find the site path. Kernel service is not always available at this Chris@0: // point, but is preferred, when available. Chris@0: if (\Drupal::hasService('kernel')) { Chris@0: $site_path = \Drupal::service('site.path'); Chris@0: } Chris@0: else { Chris@0: // If there is no kernel available yet, we call the static Chris@0: // findSitePath(). Chris@0: $site_path = DrupalKernel::findSitePath(Request::createFromGlobals()); Chris@0: } Chris@0: } Chris@0: return Settings::get('file_public_path', $site_path . '/files'); Chris@0: } Chris@0: Chris@0: }