public function BlazyManagerBase::isBlazy in Blazy 7
Same name and namespace in other branches
- 8.2 src/BlazyManagerBase.php \Drupal\blazy\BlazyManagerBase::isBlazy()
Checks for Blazy formatter such as from within a Views style plugin.
Ensures the settings traverse up to the container where Blazy is clueless. The supported plugins can add [data-blazy] attribute into its container containing $settings['blazy_data'] converted into [data-blazy] JSON. This allows Blazy Grid, or other Views styles, lacking of UI, to have additional settings extracted from the first Blazy formatter found. Such as media switch/ lightbox. This way the container can add relevant attributes to its container, etc. Also applies to entity references where Blazy is not the main formatter, instead embedded as part of the parent's.
Parameters
array $settings: The settings being modified.
array $item: The item containing settings or item keys, not image item.
Overrides BlazyManagerInterface::isBlazy
1 call to BlazyManagerBase::isBlazy()
- BlazyManager::prepareBuild in src/
BlazyManager.php - Prepares Blazy outputs, extract items, and returns updated $settings.
File
- src/
BlazyManagerBase.php, line 244
Class
- BlazyManagerBase
- Implements BlazyManagerInterface.
Namespace
Drupal\blazyCode
public function isBlazy(array &$settings, array $item = []) {
$image = isset($item['item']) ? $item['item'] : NULL;
$settings['first_item'] = $image;
// Blazy formatter within Views fields by supported modules.
if (isset($item['settings'])) {
$blazy = $item['settings'];
// Allows breakpoints overrides such as GridStack multi-styled images.
if (empty($settings['breakpoints']) && isset($blazy['breakpoints'])) {
$settings['breakpoints'] = $blazy['breakpoints'];
}
$cherries = BlazyDefault::cherrySettings() + [
'uri' => '',
];
foreach ($cherries as $key => $value) {
$fallback = isset($settings[$key]) ? $settings[$key] : $value;
$settings[$key] = isset($blazy[$key]) && empty($fallback) ? $blazy[$key] : $fallback;
}
// @todo remove first_uri for _uri for consistency.
$uri = empty($settings['first_uri']) ? $settings['uri'] : $settings['first_uri'];
$settings['_uri'] = $settings['first_uri'] = empty($settings['_uri']) ? $uri : $settings['_uri'];
unset($settings['uri']);
}
// Allows lightboxes to provide its own optionsets.
$switch = empty($settings['media_switch']) ? FALSE : $settings['media_switch'];
if ($switch) {
$settings[$switch] = empty($settings[$switch]) ? $switch : $settings[$switch];
}
// Provides data for the [data-blazy] attribute at the containing element.
// @todo TBD; for keeping or removal at blazy:7.x-2.0.
$this
->cleanUpBreakpoints($settings);
if (!empty($settings['breakpoints'])) {
$this
->buildDataBlazy($settings, $image);
}
unset($settings['first_image']);
}