Skip to content

Commit

Permalink
Add “Manage Resize for All Volumes” plugin setting and re-organise Re…
Browse files Browse the repository at this point in the history
…size settings template to better differentiate between all-volume and volume-specific settings
  • Loading branch information
engram-design committed Jul 24, 2024
1 parent 8bfccd6 commit a3ef0db
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 65 deletions.
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"

26 changes: 18 additions & 8 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 - so long as not empty, it takes precendence
// Check if there's a specific setting for the source
$sourceSettings = $settings->assetSourceSettings[$sourceId] ?? [];

if (array_key_exists($setting, $sourceSettings) && $sourceSettings[$setting] !== '') {
return $sourceSettings[$setting];
if (array_key_exists($setting, $sourceSettings)) {
$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 a3ef0db

Please sign in to comment.