Skip to content

Commit

Permalink
Merge branch 'release/5.0.1' into v5
Browse files Browse the repository at this point in the history
  • Loading branch information
khalwat committed May 9, 2024
2 parents 764542f + 646dd13 commit 67d3fde
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 16 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# ImageOptimize Changelog

## 5.0.1 - 2024.05.09
### Fixed
* Fixed an issue where field content was not propagated to other sites on multi-site installs, causing missing images
* Fixed an issue where the `.imgTag()` and `.pictureTag()` would output and invalid `style` attribute for lazy loaded images ([#400](https://github.com/nystudio107/craft-imageoptimize/issues/400))
* Fixed an issue where the Subpath wasn't being included for remote volumes like S3 & Google Cloud ([#403](https://github.com/nystudio107/craft-imageoptimize/issues/403))

## 5.0.0 - 2024.04.15
### Added
* Stable release for Craft CMS 5
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "nystudio107/craft-imageoptimize",
"description": "Automatically create & optimize responsive image transforms, using either native Craft transforms or a service like imgix, with zero template changes.",
"type": "craft-plugin",
"version": "5.0.0",
"version": "5.0.1",
"keywords": [
"craft",
"cms",
Expand Down
2 changes: 1 addition & 1 deletion src/imagetransforms/ImageTransform.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function purgeUrl(string $url): bool
public function getAssetUri(Asset $asset): ?string
{
$volume = $asset->getVolume();
$assetPath = $asset->getPath();
$assetPath = $volume->getSubpath() . $asset->getPath();

// Account for volume types with a subfolder setting
// e.g. craftcms/aws-s3, craftcms/google-cloud
Expand Down
9 changes: 5 additions & 4 deletions src/models/BaseImageTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ protected function swapLazyLoadAttrs(string $loading, string $placeHolder, array
}
// Set the style on this element to be the placeholder image as the background-image
if (isset($attrs['style']) && !empty($attrs['src'])) {
$attrs['style'] = trim(
$attrs['style'] .
'background-image:url(' . $this->getLazyLoadSrc($placeHolder) . '); background-size: cover;'
);
if (empty($attrs['style'])) {
$attrs['style'] = [];
}
$attrs['style']['background-image'] = 'url(' . $this->getLazyLoadSrc($placeHolder) . ')';
$attrs['style']['background-size'] = 'cover';
}
// Handle attributes that lazy and lazySizesFallback have in common
switch ($loading) {
Expand Down
22 changes: 12 additions & 10 deletions src/services/OptimizedImages.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,18 +291,20 @@ public function updateOptimizedImageFieldData(Field $field, ElementInterface $as
if ($field->handle !== null) {
$asset->setFieldValue($field->handle, $field->serializeValue($model, $asset));
$fieldLayout = $asset->getFieldLayout();
$siteSettingsRecord = Element_SiteSettingsRecord::findOne([
$siteSettingsRecords = Element_SiteSettingsRecord::findAll([
'elementId' => $asset->id,
'siteId' => $asset->siteId,
]);
// Set the field values
if ($siteSettingsRecord && $fieldLayout) {
$content = Json::decodeIfJson($siteSettingsRecord->content) ?: [];
$content[$field->layoutElement->uid] = $field->serializeValue($asset->getFieldValue($field->handle), $asset);
$siteSettingsRecord->content = $content;
// Save the site settings record
if (!$siteSettingsRecord->save(false)) {
Craft::error('Couldn’t save elements’ site settings record.', __METHOD__);
// Update it for all of the sites
foreach ($siteSettingsRecords as $siteSettingsRecord) {
// Set the field values
if ($siteSettingsRecord && $fieldLayout) {
$content = Json::decodeIfJson($siteSettingsRecord->content) ?: [];
$content[$field->layoutElement->uid] = $field->serializeValue($asset->getFieldValue($field->handle), $asset);
$siteSettingsRecord->content = $content;
// Save the site settings record
if (!$siteSettingsRecord->save(false)) {
Craft::error('Couldn’t save elements’ site settings record.', __METHOD__);
}
}
}
}
Expand Down

0 comments on commit 67d3fde

Please sign in to comment.