Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/craft-4' into craft-5
Browse files Browse the repository at this point in the history
# Conflicts:
#	CHANGELOG.md
#	composer.json
#	src/translations/en/image-resizer.php
  • Loading branch information
engram-design committed Aug 11, 2024
2 parents 423be42 + bc755ce commit 7ee3424
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 65 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@
- Now requires PHP `8.2.0+`.
- Now requires Craft `5.0.0+`.

## 3.0.12 - 2024-07-24

### Added
- Add “Manage Resize for All Volumes” plugin setting and re-organise Resize settings template to better differentiate between all-volume and volume-specific settings

### Changed
- Update English translations.

### Fixed
- Fix images not being resized when volume-specific settings weren’t set

## 3.0.11 - 2024-01-30

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ Image Resizer is licensed under the MIT license, meaning it will always be free
<h2></h2>

<a href="https://verbb.io" target="_blank">
<img width="100" src="https://verbb.io/assets/img/verbb-pill.svg">
<img width="101" height="33" src="https://verbb.io/assets/img/verbb-pill.svg" alt="Verbb">
</a>
11 changes: 0 additions & 11 deletions config.codekit3
Original file line number Diff line number Diff line change
Expand Up @@ -325,17 +325,6 @@
"sC" : 0,
"tS" : 0
},
"\/src\/resources\/src\/js\/_settings.js" : {
"bF" : 0,
"ft" : 64,
"ma" : 1,
"mi" : 1,
"oA" : 1,
"oAP" : "\/src\/resources\/dist\/js\/_settings.js",
"oF" : 0,
"sC" : 0,
"tS" : 0
},
"\/src\/resources\/src\/js\/_tabs.js" : {
"bF" : 0,
"ft" : 64,
Expand Down
1 change: 1 addition & 0 deletions src/models/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class Settings extends Model
// Properties
// =========================================================================

public bool $useGlobalSettings = true;
public bool $enabled = true;
public int $imageWidth = 2048;
public int $imageHeight = 2048;
Expand Down
2 changes: 1 addition & 1 deletion src/resources/dist/js/image-resizer.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/resources/dist/js/image-resizer.js.map

Large diffs are not rendered by default.

36 changes: 0 additions & 36 deletions src/resources/src/js/_settings.js

This file was deleted.

1 change: 0 additions & 1 deletion src/resources/src/js/image-resizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@
// ==========================================================================

// @codekit-prepend "_tabs.js"
// @codekit-prepend "_settings.js"
// @codekit-prepend "_resize-element-action.js"

24 changes: 17 additions & 7 deletions src/services/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,30 @@ public function getSettingForAssetSource($sourceId, string $setting): mixed
/* @var Settings $settings */
$settings = ImageResizer::$plugin->getSettings();

// If the plugin itself is disabled, return nothing.
if (!$settings->enabled) {
return null;
// Check if we're using the global settings (all volumes the same), they're priority
if ($settings->useGlobalSettings) {
return $settings->$setting;
}

// Check if there's a specific setting for the source - no matter what it is, it takes precendence
// Check if there's a specific setting for the source
$sourceSettings = $settings->assetSourceSettings[$sourceId] ?? [];

if (array_key_exists($setting, $sourceSettings)) {
return $sourceSettings[$setting];
$fallback = null;

// Some settings should fallback to the all-asset setting when empty, because of how the UI works
if ($setting === 'imageWidth') {
$fallback = $settings->imageWidth;
} else if ($setting === 'imageHeight') {
$fallback = $settings->imageHeight;
} else if ($setting === 'imageQuality') {
$fallback = $settings->imageQuality;
}

return $sourceSettings[$setting] ?: $fallback;
}

// Otherwise, fall back to the default, global setting for all sources.
return $settings->$setting;
return null;
}

/**
Expand Down
29 changes: 22 additions & 7 deletions src/templates/settings/_panes/resize.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@
sourceOptions: sourceOptions,
} %}

<h2>{{ "All Asset Source Settings" | t('image-resizer') }}</h2>

{{ macros.resizeSetting(settings, additionalSettings) }}
{{ forms.lightswitchField({
label: 'Manage Resize for All Volumes' | t('image-resizer'),
instructions: 'Whether you want to manage image resize settings for all asset volumes, or manage them individually for each volume.' | t('image-resizer'),
id: 'useGlobalSettings',
name: 'useGlobalSettings',
on: settings.useGlobalSettings,
warning: macros.configWarning('useGlobalSettings', 'image-resizer'),
toggle: 'all-volume-settings',
reverseToggle: 'volume-settings'
}) }}

{{ forms.lightswitchField({
label: 'Skip larger resulting images' | t('image-resizer'),
Expand All @@ -27,12 +34,20 @@ <h2>{{ "All Asset Source Settings" | t('image-resizer') }}</h2>
warning: macros.configWarning('nonDestructiveResize', 'image-resizer'),
}) }}

<div id="assetSources">
{% for item in sourceOptions %}
<hr>
<hr>

<h2>{{ "{label} Asset Source Settings" | t('image-resizer', { label: item.label }) }}</h2>
<div id="all-volume-settings">
<h2>{{ 'All Asset Volume Settings' | t('image-resizer') }}</h2>

{{ macros.resizeSetting(settings, additionalSettings) }}
</div>

<div id="volume-settings">
{% for item in sourceOptions %}
<h2>{{ "“{label}” Asset Volume Settings" | t('image-resizer', { label: item.label }) }}</h2>

{{ macros.resizeSetting(settings, additionalSettings, item) }}

{{ not loop.last ? '<hr>' }}
{% endfor %}
</div>

0 comments on commit 7ee3424

Please sign in to comment.