public function BlazyManagerBase::attach in Blazy 7
Same name and namespace in other branches
- 8.2 src/BlazyManagerBase.php \Drupal\blazy\BlazyManagerBase::attach()
- 8 src/BlazyManagerBase.php \Drupal\blazy\BlazyManagerBase::attach()
Returns array of needed assets suitable for #attached property.
Return value
array Returns the required library array.
Overrides BlazyManagerInterface::attach
1 call to BlazyManagerBase::attach()
- BlazyManager::setAttachments in src/
BlazyManager.php - Provides attachment and cache for both theme_field() and theme_item_list().
File
- src/
BlazyManagerBase.php, line 89
Class
- BlazyManagerBase
- Implements BlazyManagerInterface.
Namespace
Drupal\blazyCode
public function attach(array $attach) {
$load = [];
$lazy = !empty($attach['blazy']) || isset($attach['lazy']) && $attach['lazy'] == 'blazy';
// Allow both variants of grid or column to co-exist for different fields.
if (!empty($attach['style'])) {
foreach ([
'column',
'grid',
] as $grid) {
$attach[$grid] = $attach['style'];
}
}
if (!empty($attach['fx']) && $attach['fx'] == 'blur') {
$load['library'][] = [
'blazy',
'fx.blur',
];
}
foreach ([
'column',
'filter',
'grid',
'media',
'ratio',
] as $component) {
if (!empty($attach[$component])) {
$load['library'][] = [
'blazy',
$component,
];
}
}
foreach ([
'lightbox',
'colorbox',
'photobox',
] as $box) {
if (!empty($attach[$box])) {
$load['library'][] = [
'blazy',
$box,
];
}
}
// Picture integration.
if (!empty($attach['resimage'])) {
$load['library'][] = [
'picture',
'picturefill_head',
];
$load['library'][] = [
'picture',
'picturefill',
];
$load['library'][] = [
'picture',
'picture.ajax',
];
if ($lazy) {
$load['library'][] = [
'picture',
'lazysizes',
];
$load['library'][] = [
'picture',
'lazysizes_aspect_ratio',
];
}
}
// Core Blazy libraries, enforced to prevent JS error when optional.
$load['js'][] = [
'data' => [
'blazy' => $this
->config('blazy', BlazyDefault::formSettings()['blazy']),
'blazyIo' => $this
->getIoSettings($attach),
],
'type' => 'setting',
];
$load['library'][] = [
'blazy',
'load',
];
// Adds AJAX helper to revalidate IO, if using IO with VIS, or alike.
if (!empty($attach['use_ajax'])) {
$load['library'][] = [
'blazy',
'bio.ajax',
];
}
drupal_alter('blazy_attach', $load, $attach);
return $load;
}