Skip to content

Commit

Permalink
(v2.3.0) Allows comma-separated file paths
Browse files Browse the repository at this point in the history
  • Loading branch information
lindseydiloreto committed Dec 18, 2020
1 parent e80b0ec commit 4c1ecb0
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 11 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
# Changelog

## 2.3.0 - 2020-12-18

### Added
- Now allows for multiple, comma-separated file paths. (thanks @nickolasjadams)

## 2.2.1 - 2020-04-04

### Changed
- Made the viewing area larger.
- Made the viewing area larger. (thanks @SayChi)

## 2.2.0 - 2019-06-24

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Easily overwrite the default Control Panel styles that ship with Craft.

After you've installed the plugin, go to:

- **Settings > Plugins > Control Panel CSS**
- **Settings > Control Panel CSS**

Your custom CSS can be saved in either (or both) of two places:

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": "doublesecretagency/craft-cpcss",
"description": "Add custom CSS to your Control Panel.",
"type": "craft-plugin",
"version": "2.2.1",
"version": "2.3.0",
"keywords": [
"craft",
"cms",
Expand Down
4 changes: 2 additions & 2 deletions src/templates/settings.twig
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
<p>Your custom CSS will be applied to the entire Control Panel.</p>

{{ forms.autosuggestField({
label: "CSS File"|t,
instructions: "Enter the path to your CSS file."|t,
label: "CSS File(s)"|t,
instructions: "Enter the path to a separate CSS file. Multiple paths may be separated with commas. You may use aliases (ie: @web) in your filepath."|t,
id: 'cssFile',
name: 'cssFile',
suggestEnvVars: true,
Expand Down
32 changes: 26 additions & 6 deletions src/web/assets/CustomAssets.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,43 @@ public function init()
{
parent::init();

// Requires standard CP assets to be loaded first
$this->depends = [CpAsset::class];

// Get plugin settings
$settings = CpCss::$plugin->getSettings();

$file = trim(Craft::parseEnv($settings['cssFile']));
// Get the file (or files) specified
$file = trim($settings['cssFile']);

if ($file) {
// If no file was specified, bail
if (!$file) {
return;
}

// Initialize a collection of paths
$paths = [];

// Allow for comma-separated file paths
$files = explode(',', $file);

// Loop through specified files
foreach ($files as $file) {

// Cache buster
// Parse each filename for aliases
$file = Craft::parseEnv(trim($file));

// Bust the cache
if ($hash = @sha1_file($file)) {
$file .= '?e='.$hash;
}

// Load CSS file
$this->css = [$file];

// Add file to path collection
$paths[] = $file;
}

// Load all files
$this->css = $paths;
}

}

0 comments on commit 4c1ecb0

Please sign in to comment.