Skip to content

Commit

Permalink
Merge pull request #122 from craftpulse/v4-develop
Browse files Browse the repository at this point in the history
4.5.1
  • Loading branch information
cookie10codes authored Apr 8, 2024
2 parents c4ea8c3 + 5725924 commit f838688
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/).

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

## 4.5.0 - 2024-03-02
### Changed
- Changed code according to PHPStan advise (prep for Craft 5)
Expand Down Expand Up @@ -109,4 +113,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": "4.5.0",
"version": "4.5.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 @@ -143,8 +143,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 f838688

Please sign in to comment.