Skip to content

Commit

Permalink
Merge pull request #123 from craftpulse/v5-develop
Browse files Browse the repository at this point in the history
5.0.1
  • Loading branch information
cookie10codes authored Apr 8, 2024
2 parents 47f8503 + 80c9aa9 commit 52e9d43
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).

## 5.0.1 - 2024-03-08
### Fixed
- Fixed the default fetch if the default isn't the first one in the config list

## 5.0.0 - 2024-03-02
### Added
- Provided support for Craft 5 (tanks to [@marknotton-yello](https://github.com/marknotton-yello))
Expand Down Expand Up @@ -113,4 +117,4 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
- Updated Types

### Removed
- Removed unused element class
- Removed unused element class
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": "craftpulse/craft-colour-swatches",
"description": "Let clients choose from a predefined set of colours and utilise associated colour codes and class names in your templates.",
"type": "craft-plugin",
"version": "5.0.0",
"version": "5.0.1",
"keywords": [
"craft",
"cms",
Expand Down
8 changes: 6 additions & 2 deletions src/fields/ColourSwatches.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,12 @@ public function normalizeValue(mixed $value, ?ElementInterface $element = null):
// if default is set --> return default
$default = array_filter($this->options, function($option) {return $option['default'] == 1;});

if (is_array($default) && count($default) > 0) {
return new ColourSwatchesModel(Json::encode($default[0]));
if (!is_null($default) && count($default) > 0) {
try {
return new ColourSwatchesModel(Json::encode(current($default)));
} catch(\ErrorException) {
Craft::error("There's no default colour defined");
}
}

// if no default is set --> return null
Expand Down

0 comments on commit 52e9d43

Please sign in to comment.