class PhotoswipeAssetsManager in PhotoSwipe 8
Same name and namespace in other branches
- 8.2 src/PhotoswipeAssetsManager.php \Drupal\photoswipe\PhotoswipeAssetsManager
- 3.x src/PhotoswipeAssetsManager.php \Drupal\photoswipe\PhotoswipeAssetsManager
Photoswipe asset manager.
Hierarchy
- class \Drupal\photoswipe\PhotoswipeAssetsManager implements PhotoswipeAssetsManagerInterface
Expanded class hierarchy of PhotoswipeAssetsManager
1 string reference to 'PhotoswipeAssetsManager'
1 service uses PhotoswipeAssetsManager
File
- src/
PhotoswipeAssetsManager.php, line 11
Namespace
Drupal\photoswipeView source
class PhotoswipeAssetsManager implements PhotoswipeAssetsManagerInterface {
/**
* Whether the assets were attached somewhere in this request or not.
*
* @var bool
*/
protected $attached;
/**
* Photoswipe config.
*
* @var \Drupal\Core\Config\ImmutableConfig
*/
protected $config;
/**
* The renderer.
*
* @var \Drupal\Core\Render\RendererInterface
*/
protected $renderer;
/**
* Creates a \Drupal\photoswipe\PhotoswipeAssetsManager.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config
* The config factory.
* @param \Drupal\Core\Render\RendererInterface $renderer
* The renderer service.
*/
public function __construct(ConfigFactoryInterface $config, RendererInterface $renderer) {
$this->config = $config
->get('photoswipe.settings');
$this->renderer = $renderer;
}
/**
* {@inheritdoc}
*/
public function attach(array &$element) {
// Add the library of Photoswipe assets.
$element['#attached']['library'][] = 'photoswipe/photoswipe';
// Load initialization file.
$element['#attached']['library'][] = 'photoswipe/photoswipe.init';
// Add photoswipe js settings.
$options = $this->config
->get('options');
// Allow other modules to alter / extend the options to pass to photoswipe
// JavaScript.
\Drupal::moduleHandler()
->alter('photoswipe_js_options', $options);
$element['#attached']['drupalSettings']['photoswipe']['options'] = $options;
// Add photoswipe container with class="pswp".
$template = [
"#theme" => 'photoswipe_container',
];
$element['#attached']['drupalSettings']['photoswipe']['container'] = $this->renderer
->renderPlain($template);
$this->attached = TRUE;
}
/**
* {@inheritdoc}
*/
public function isAttached() {
return $this->attached;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PhotoswipeAssetsManager:: |
protected | property | Whether the assets were attached somewhere in this request or not. | |
PhotoswipeAssetsManager:: |
protected | property | Photoswipe config. | |
PhotoswipeAssetsManager:: |
protected | property | The renderer. | |
PhotoswipeAssetsManager:: |
public | function |
Attach photoswipe assets. Overrides PhotoswipeAssetsManagerInterface:: |
|
PhotoswipeAssetsManager:: |
public | function |
Are photoswipe assets attached to this page in this request?. Overrides PhotoswipeAssetsManagerInterface:: |
|
PhotoswipeAssetsManager:: |
public | function | Creates a \Drupal\photoswipe\PhotoswipeAssetsManager. |