Skip to content

Commit

Permalink
Merge pull request #136 from craftpulse/v4-develop
Browse files Browse the repository at this point in the history
4.5.3
  • Loading branch information
cookie10codes authored Sep 23, 2024
2 parents c62024d + 945c16f commit bb0f476
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ 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.3 - 2024-09-23
### Fixed
- Undefined Array Key 0 Error in Craft 5.36 Colour Swatches 5.0.2 #133
- Error occurs when entering colors directly in the CMS field #127

## 4.5.2 - 2024-04-15
### Fixed
- Fixed the bug when default color isn't the first in array #124
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.2",
"version": "4.5.3",
"keywords": [
"craft",
"cms",
Expand Down
10 changes: 8 additions & 2 deletions src/fields/ColourSwatches.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,16 @@ public function serializeValue(mixed $value, ?ElementInterface $element = null):
if (!$saveValue) {

if (is_null($this->default)) {
$default = array_filter($settingsPalette, function($option) {return $option['default'] == true;});
$array_filter = [];
foreach ($settingsPalette as $key => $option) {
if ($option['default']) {
$array_filter[$key] = $option;
}
}
$default = $array_filter;

if (!is_null($default) && count($default) > 0) {
$this->default = $default[0]['label'];
$this->default = array_values($default)[0]['label'];
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/models/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Settings extends Model
protected function defineRules(): array
{
return [
[['colors', 'palettes'], 'required'],
// [['colors', 'palettes'], 'required'],
[['colors', 'palettes'], function ($attribute, $params) {
if (!is_array($this->colors)) {
$this->addError('colors', Craft::t('colour-swatches', 'colors is not array!'));
Expand All @@ -49,7 +49,7 @@ protected function defineRules(): array
}
}
}

return $palettes;
}]
];
Expand Down
2 changes: 1 addition & 1 deletion src/templates/input.twig
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
{# : field.options %}#}

{% if options|length == 0 %}
<p>{{ "The selected colour palette for this field isn\'t defined in the `colour-swatches.php` config file"|t('colour-swatches') }}</p>
<p>{{ "The selected colour palette for this field isn\'t defined in the `colour-swatches.php` config file or settings."|t('colour-swatches') }}</p>
{% endif %}

<div id="{{ id }}" class="color-swatches">
Expand Down

0 comments on commit bb0f476

Please sign in to comment.