public function BlazyFilter::getImageItemFromImageSrc in Blazy 8.2
Returns the faked image item from SRC.
Parameters
array $settings: The content array being modified.
object $node: The HTML DOM object.
string $src: The corrected SRC value.
Return value
object The faked or file entity image item.
Overrides BlazyFilterInterface::getImageItemFromImageSrc
1 call to BlazyFilter::getImageItemFromImageSrc()
- BlazyFilter::buildImageItem in src/
Plugin/ Filter/ BlazyFilter.php - Returns the faked image item for the image, uploaded or hard-coded.
File
- src/
Plugin/ Filter/ BlazyFilter.php, line 440
Class
- BlazyFilter
- Provides a filter to lazyload image, or iframe elements.
Namespace
Drupal\blazy\Plugin\FilterCode
public function getImageItemFromImageSrc(array &$settings, $node, $src) {
$data['item'] = NULL;
$uuid = $node
->hasAttribute('data-entity-uuid') ? $node
->getAttribute('data-entity-uuid') : '';
// Uploaded image has UUID with file API.
if ($uuid && ($file = $this->blazyManager
->getEntityRepository()
->loadEntityByUuid('file', $uuid))) {
$data = $this->blazyOembed
->getImageItem($file);
if (isset($data['settings'])) {
$settings = array_merge($settings, $data['settings']);
}
}
else {
// Manually hard-coded image has no UUID, nor file API.
$settings['uri'] = $src;
// Attempts to get the correct URI with hard-coded URL if applicable.
if ($uri = BlazyUtil::buildUri($src)) {
$settings['uri'] = $uri;
$data['item'] = Blazy::image($settings);
}
else {
// At least provide root URI to figure out image dimensions.
$settings['uri_root'] = mb_substr($src, 0, 4) === 'http' ? $src : $this->root . $src;
}
}
return $data['item'];
}