Skip to content

Commit

Permalink
Merge pull request #126 from craftpulse/v4-develop
Browse files Browse the repository at this point in the history
V4 develop
  • Loading branch information
cookie10codes authored Apr 15, 2024
2 parents f838688 + 8723b28 commit c62024d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 4 additions & 0 deletions 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.2 - 2024-04-15
### Fixed
- Fixed the bug when default color isn't the first in array #124

## 4.5.1 - 2024-03-08
### Fixed
- Fixed the default fetch if the default isn't the first one in the config list
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": "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.1",
"version": "4.5.2",
"keywords": [
"craft",
"cms",
Expand Down
8 changes: 2 additions & 6 deletions src/fields/ColourSwatches.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,8 @@ 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_null($default) && count($default) > 0) {
try {
return new ColourSwatchesModel(Json::encode(current($default)));
} catch(\ErrorException) {
Craft::error("There's no default colour defined");
}
if (is_array($default) && count($default) > 0) {
return new ColourSwatchesModel(Json::encode(array_values($default)[0]));
}

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

0 comments on commit c62024d

Please sign in to comment.