class ThemePreprocess in Image Lazyloader 8
Class ThemePreprocess.
Hierarchy
- class \Drupal\lazyloader\ThemePreprocess
Expanded class hierarchy of ThemePreprocess
1 file declares its use of ThemePreprocess
- ThemePreprocessTest.php in tests/
src/ Unit/ ThemePreprocessTest.php
1 string reference to 'ThemePreprocess'
1 service uses ThemePreprocess
File
- src/
ThemePreprocess.php, line 10
Namespace
Drupal\lazyloaderView source
class ThemePreprocess {
/**
* The config factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* Creates a new ThemePreprocess instance.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory.
*/
public function __construct(ConfigFactoryInterface $config_factory) {
$this->configFactory = $config_factory;
}
/**
* Attaches the Lazyloader library to a render array.
*
* @param array $vars
* The render array.
*
* @return array
* The render array with added library.
*/
public function attachLibrary(array $vars) {
$config = $this->configFactory
->get('lazyloader.configuration');
if (!$config
->get('enabled')) {
return $vars;
}
$vars['#attached']['library'][] = $this
->determineLibraryToAttach();
return $vars;
}
/**
* Adds the cache tags.
*
* @param array $vars
* The variables.
*
* @return array
* The input array with cache tags.
*/
public function addCacheTags(array $vars) {
$vars['#cache']['tags'][] = 'config:lazyloader.configuration';
return $vars;
}
/**
* Determines the library to attach.
*
* @return string
* The library to attach.
*/
private function determineLibraryToAttach() {
$config = $this->configFactory
->get('lazyloader.configuration');
if ($config
->get('debugging')) {
$library = 'lazyloader/lazysizes';
return $library;
}
if ($config
->get('cdn') || !file_exists('libraries/lazysizes/lazysizes.min.js')) {
$library = 'lazyloader/lazysizes-min.cdn';
return $library;
}
$library = 'lazyloader/lazysizes-min';
return $library;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ThemePreprocess:: |
protected | property | The config factory. | |
ThemePreprocess:: |
public | function | Adds the cache tags. | |
ThemePreprocess:: |
public | function | Attaches the Lazyloader library to a render array. | |
ThemePreprocess:: |
private | function | Determines the library to attach. | |
ThemePreprocess:: |
public | function | Creates a new ThemePreprocess instance. |