-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Craft 4 compatibility, add settings and query parameter support
- Loading branch information
1 parent
9125a4a
commit fa91262
Showing
11 changed files
with
170 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,40 @@ | ||
# Assets Autoversioning Changelog | ||
|
||
## Unreleased | ||
## 2.0.0 - 2022-05-04 | ||
|
||
### Added | ||
|
||
- Craft CMS 4 compatibility. | ||
- Settings page. | ||
- Switch to activate/deactivate versioning. Can be set via environment variable. | ||
- The file with the build ID to use as version is now configurable. | ||
- Use query parameter instead of file suffix when adding the version to an asset. | ||
|
||
### Changed | ||
- Fixed background color of icon | ||
|
||
- Requires Craft CMS >= 4.0 | ||
|
||
## 1.0.3 - 2019-04-06 | ||
|
||
### Changed | ||
|
||
- New icon | ||
- Updated documentation | ||
|
||
## 1.0.2 - 2019-01-09 | ||
|
||
### Removed | ||
|
||
- Removed version number | ||
|
||
## 1.0.1 - 2018-12-19 | ||
|
||
### Changed | ||
|
||
- Fix version number | ||
|
||
## 1.0.0 - 2018-12-19 | ||
|
||
### Added | ||
|
||
- Initial release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,84 @@ | ||
<?php | ||
/** | ||
* Craft3 Assets Autoversioning plugin for Craft CMS 3.x | ||
* | ||
* A Twig extension for CraftCMS (Craft3.x) that helps you cache-bust your assets | ||
* | ||
* @link https://www.codemonauts.com | ||
* @copyright Copyright (c) 2018 Codemonauts | ||
*/ | ||
|
||
namespace codemonauts\autoversioning; | ||
|
||
use codemonauts\autoversioning\models\Settings; | ||
use codemonauts\autoversioning\twigextensions\AutoversioningTwigExtension; | ||
|
||
use Craft; | ||
use craft\base\Model; | ||
use craft\base\Plugin; | ||
use craft\services\Plugins; | ||
use craft\events\PluginEvent; | ||
|
||
use yii\base\Event; | ||
|
||
/** | ||
* Class Craft3AssetsAutoversioning | ||
* | ||
* @author Codemonauts | ||
* @package Craft3AssetsAutoversioning | ||
* @since 0.1 | ||
* | ||
*/ | ||
use craft\helpers\UrlHelper; | ||
|
||
class Autoversioning extends Plugin | ||
{ | ||
// Static Properties | ||
// ========================================================================= | ||
|
||
/** | ||
* @var Autoversioning | ||
*/ | ||
public static $plugin; | ||
public static Autoversioning $plugin; | ||
|
||
// Public Properties | ||
// ========================================================================= | ||
/** | ||
* @var \codemonauts\autoversioning\models\Settings|null | ||
*/ | ||
public static ?Settings $settings; | ||
|
||
/** | ||
* @var string | ||
* @inheritDoc | ||
*/ | ||
public $schemaVersion = '0.1'; | ||
public bool $hasCpSettings = true; | ||
|
||
// Public Methods | ||
// ========================================================================= | ||
/** | ||
* @var string | ||
*/ | ||
public string $schemaVersion = '0.1'; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function init() | ||
{ | ||
parent::init(); | ||
|
||
self::$plugin = $this; | ||
|
||
self::$settings = self::$plugin->getSettings(); | ||
|
||
// Register Twig extension | ||
Craft::$app->view->registerTwigExtension(new AutoversioningTwigExtension()); | ||
} | ||
|
||
Event::on( | ||
Plugins::class, | ||
Plugins::EVENT_AFTER_INSTALL_PLUGIN, | ||
function (PluginEvent $event) { | ||
if ($event->plugin === $this) { | ||
} | ||
} | ||
); | ||
/** | ||
* @inheritDoc | ||
*/ | ||
public function afterInstall(): void | ||
{ | ||
parent::afterInstall(); | ||
|
||
Craft::info( | ||
Craft::t( | ||
'craft3-assets-autoversioning', | ||
'{name} plugin loaded', | ||
['name' => $this->name] | ||
), | ||
__METHOD__ | ||
); | ||
if (Craft::$app->getRequest()->getIsConsoleRequest()) { | ||
return; | ||
} | ||
|
||
Craft::$app->getResponse()->redirect( | ||
UrlHelper::cpUrl('settings/plugins/craft3-assets-autoversioning') | ||
)->send(); | ||
} | ||
|
||
// Protected Methods | ||
// ========================================================================= | ||
/** | ||
* @inheritDoc | ||
*/ | ||
protected function createSettingsModel(): ?Model | ||
{ | ||
return new Settings(); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
protected function settingsHtml(): ?string | ||
{ | ||
return Craft::$app->getView()->renderTemplate('craft3-assets-autoversioning/settings', [ | ||
'settings' => $this->getSettings(), | ||
] | ||
); | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace codemonauts\autoversioning\models; | ||
|
||
use craft\base\Model; | ||
|
||
class Settings extends Model | ||
{ | ||
/** | ||
* @var string File to check for build ID | ||
*/ | ||
public string $ciFile = '@root/build.txt'; | ||
|
||
/** | ||
* @var bool Switch to activate versioning | ||
*/ | ||
public bool $active = true; | ||
|
||
/** | ||
* @var bool Use query parameter instead of path | ||
*/ | ||
public bool $useQueryParam = false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{% import "_includes/forms" as forms %} | ||
|
||
{{ forms.booleanMenuField({ | ||
label: 'Active'|t('craft3-assets-autoversioning'), | ||
id: 'active', | ||
name: 'active', | ||
value: settings.active, | ||
includeEnvVars: true, | ||
required: true, | ||
errors: settings.getErrors('active') | ||
}) }} | ||
|
||
{{ forms.autosuggestField({ | ||
label: 'CI File'|t('craft3-assets-autoversioning'), | ||
id: 'ciFile', | ||
name: 'ciFile', | ||
instructions: 'The file containing the build ID to use as version number. Leave empty to always use the modification time of the asset.'|t('craft3-assets-autoversioning'), | ||
value: settings.ciFile, | ||
suggestEnvVars: true, | ||
suggestAliases: true, | ||
type: 'text', | ||
errors: settings.getErrors('ciFile') | ||
}) }} | ||
|
||
{{ forms.lightswitchField({ | ||
label: 'Use query parameter'|t("craft3-assets-autoversioning"), | ||
instructions: 'Use query parameter instead of file suffix for versioning.'|t('craft3-assets-autoversioning'), | ||
id: 'useQueryParam', | ||
name: 'useQueryParam', | ||
on: settings.useQueryParam, | ||
required: true, | ||
errors: settings.getErrors('useQueryParam') | ||
}) }} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.