Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release/1.5.0 #57

Merged
merged 16 commits into from
Nov 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,22 @@ 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/).

## 1.4.0 - 2020-9-11 Bugfix
Migrate namespace from rias to percipioglobal after upgrade. Also converted config php to 'colors' instead of 'colours'. Still supports 'colours' for older versions.
Fixes issues (#36, #50)

## 1.3.3 - 2020-8-19 Bugfix
Fixed bugs introduced in last release by not checking the default configuration settings - Apologies. New features coming in next release!
Fixes issues (#44, #45, #46, #47)

## 1.3.2 - 2020-8-13 Bugfix
ElementInterface updated to allow colour preview for custom arrays. Fixes issue #42
fieldValue conditions for standard colour strings udpated to reflect null update in version 1.3.1. Fixes issue #43
fieldValue conditions for standard colour strings updated to reflect null update in version 1.3.1. Fixes issue #43


## 1.3.1 - 2020-8-03 Bugfix
Updated save function to ensure custom array fields remain selected on resave / edit
Allowed swtch between config or palette option in field settings
Allowed switch between config or palette option in field settings

## 1.3.0.1 - 2020-7-31 HOTFIX
temp fixed broken settings page, expect more robust repair next week :)
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ Take a look at the [config file](https://github.com/percipioglobal/craft-colour-
```php
return [
// Predefined colours, fixed options [label, colour, default (boolean)]
'colours' => [
'colors' => [
[
'label' => 'red',
'label' => 'red',
'color' => '#F56565',
'default' => true,
],
Expand Down Expand Up @@ -116,7 +116,7 @@ return [
[
'color' => '#4299E1', // the colour shown in the fieldtype (required)
'class' => 'blue-500', // custom attribute
'btnClass' => 'teal-500', // custom attribute
'btnClass' => 'teal-500', // custom attribute
],
]
],
Expand All @@ -127,14 +127,14 @@ return [
[
'color' => '#ED64A6', // the colour shown in the fieldtype (required)
'class' => 'pink-500', // custom attribute
'btnClass' => 'blue-500', // custom attribute
'btnClass' => 'blue-500', // custom attribute
],
]
],
],
'Gradients' => [
'Gradients' => [ // custom label
[
'label' => 'primary',
'label' => 'primary',
'default' => false,
'color' => [
[
Expand Down Expand Up @@ -176,7 +176,7 @@ You can access both the label and color in your template. By default, the label
{{ fieldName.label }}
{{ fieldName.labels }} {# Returns an array of all labels #}
{{ fieldName.color }}
{{ fieldName.colours }} {# Returns an array of all colours #}
{{ fieldName.colors }} {# Returns an array of all colours #}
```
OR to access custom attributes from the config file

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "percipioglobal/craft-colour-swatches",
"description": "Let clients choose from a predefined set of colours.",
"type": "craft-plugin",
"version": "1.3.3",
"version": "1.4.0",
"keywords": [
"craft",
"cms",
Expand Down Expand Up @@ -32,7 +32,7 @@
"extra": {
"name": "Colour Swatches",
"handle": "colour-swatches",
"schemaVersion": "1.0.0",
"schemaVersion": "1.4.0",
"hasCpSettings": false,
"hasCpSection": false,
"changelogUrl": "https://raw.githubusercontent.com/percipioglobal/craft-colour-swatches/master/CHANGELOG.md",
Expand Down
1 change: 1 addition & 0 deletions src/ColourSwatches.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use craft\base\Plugin;
use craft\events\RegisterComponentTypesEvent;
use craft\services\Fields;
use craft\services\Plugins;
use percipioglobal\colourswatches\fields\ColourSwatches as ColourSwatchesField;
use percipioglobal\colourswatches\models\Settings;
use yii\base\Event;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,9 @@

.color-swatches button.active {
box-shadow: 0 0 0 3px #F2842D;
}

.color-swatches pre {
font-size: 0.75rem;
font-family: courier;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ ColourSelectInput = Garnish.Base.extend({
{
var $option = $(ev.currentTarget);

// enables toggle on/off function of color buttons
if ($option.hasClass('active'))
{
$option.removeClass('active');
Expand Down
30 changes: 15 additions & 15 deletions src/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
return [

// Predefined colours
'colours' => [
'colors' => [
[
'label' => 'red',
'label' => 'red',
'color' => '#F56565',
'class' => 'red-500', // custom attribute
'default' => true,
Expand Down Expand Up @@ -90,9 +90,9 @@
'default' => true,
'color' => [
[
'color' => '#38B2AC', // the colour shown in the fieldtype (required)
'class' => 'teal-500', // custom attribute
'btnClass' => 'blue-500', // custom attribute,
'color' => '#38B2AC', // the color shown in the fieldtype (required)
'class' => 'teal-500', // custom attribute
'btnClass' => 'blue-500', // custom attribute,
],
]
],
Expand All @@ -101,9 +101,9 @@
'default' => false,
'color' => [
[
'color' => '#4299E1', // the colour shown in the fieldtype (required)
'color' => '#4299E1', // the color shown in the fieldtype (required)
'class' => 'blue-500', // custom attribute
'btnClass' => 'teal-500', // custom attribute
'btnClass' => 'teal-500', // custom attribute
],
]
],
Expand All @@ -112,23 +112,23 @@
'default' => false,
'color' => [
[
'color' => '#ED64A6', // the colour shown in the fieldtype (required)
'color' => '#ED64A6', // the color shown in the fieldtype (required)
'class' => 'pink-500', // custom attribute
'btnClass' => 'blue-500', // custom attribute
'btnClass' => 'blue-500', // custom attribute
],
]
],
],
'Gradients' => [
'Gradients' => [ // custom label
[
'label' => 'primary',
'label' => 'primary',
'default' => true,
'color' => [
[
'color' => '#38B2AC', // the colour shown in the fieldtype (required)
'color' => '#38B2AC', // the color shown in the fieldtype (required)
],
[
'color' => '#434190', // the next colour in this loop
'color' => '#434190', // the next color in this loop
],
]
],
Expand All @@ -137,10 +137,10 @@
'default' => false,
'color' => [
[
'color' => '#434190', // the colour shown in the fieldtype (required)
'color' => '#434190', // the color shown in the fieldtype (required)
],
[
'color' => '#ED64A6', // the next colour in this loop
'color' => '#ED64A6', // the next color in this loop
],
]
],
Expand Down
63 changes: 39 additions & 24 deletions src/fields/ColourSwatches.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class ColourSwatches extends Field implements PreviewableFieldInterface
*/
public static function displayName(): string
{
return Craft::t('colour-swatches', 'Colour Swatches');
return Craft::t('colour-swatches', 'Color Swatches');
}

// Public Methods
Expand Down Expand Up @@ -83,23 +83,24 @@ public function getContentColumnType(): string
*/
public function normalizeValue($value, ElementInterface $element = null)
{

if ($value instanceof ColourSwatchesModel) {
return $value;
}

return new ColourSwatchesModel($value);
// quick array transform so that we can ensure and `required fields` fire an error
$valueData = (array)json_decode($value);
// if we have actual data return model
if(count($valueData) > 0) {
return new ColourSwatchesModel($value);
}
}

/**
* {@inheritdoc}
*/
public function serializeValue($value, ElementInterface $element = null)
{
if ($value instanceof ColourSwatchesModel) {
return $value;
}

return new ColourSwatchesModel($value);
return $value;
}

/**
Expand All @@ -114,7 +115,7 @@ public function getSettingsHtml()
} elseif ($this->palette) {
$rows = Plugin::$plugin->settings->palettes[$this->palette];
} else {
$rows = Plugin::$plugin->settings->colours;
$rows = Plugin::$plugin->settings->colors ? Plugin::$plugin->settings->colors : Plugin::$plugin->settings->colours;
}

$config = [
Expand Down Expand Up @@ -172,7 +173,7 @@ public function getSettingsHtml()
[
'field' => $this,
'config' => $config,
'configOptions' => Plugin::$plugin->settings->colours,
'configOptions' => Plugin::$plugin->settings->colors ? Plugin::$plugin->settings->colors : Plugin::$plugin->settings->colours,
'paletteOptions' => $paletteOptions,
'palettes' => Plugin::$plugin->settings->palettes,
]
Expand All @@ -185,6 +186,7 @@ public function getSettingsHtml()
public function getInputHtml($value, ElementInterface $element = null): string
{
// Register our asset bundle
// print_r($value);
Craft::$app->getView()->registerAssetBundle(ColourSwatchesFieldAsset::class);

// Get our id and namespace
Expand All @@ -202,7 +204,7 @@ public function getInputHtml($value, ElementInterface $element = null): string
'field' => $this,
'id' => $id,
'namespacedId' => $namespacedId,
'configOptions'=> Plugin::$plugin->settings->colours,
'configOptions'=> Plugin::$plugin->settings->colors ? Plugin::$plugin->settings->colors : Plugin::$plugin->settings->colours,
'palettes' => Plugin::$plugin->settings->palettes,
]
);
Expand All @@ -212,19 +214,32 @@ public function getInputHtml($value, ElementInterface $element = null): string
* {@inheritdoc}
*/
public function getTableAttributeHtml($value, ElementInterface $element): string
{
/** @var ColorData|null $value */
$fieldValue;
if (!$value) {
return '<div class="color small static"><div class="color-preview"></div></div>';
{
// our preview no data value
$color = null;
$style="background-color: transparent";
// if we have data
if(!empty($value)){
$fieldValue = get_object_vars($value);
$gradients = array();
// if we have a custom color config
if (is_array($value->color)) {
foreach ($value->color as $color){
$gradients[] = $color->color;
}
// set a fallback if we only have one colour
$style="background-color:$gradients[0]";
// else build the gradient
if(count($gradients) > 1){
$gradients = implode(",", $gradients);
$style="background: linear-gradient(to bottom right, $gradients);";
}
// if we're using the CP values
} else {
$color = $value->color;
$style="background-color:$color";
}
}
if (is_array($value->color)) {
$fieldValue = $value->color[0]->color;
} else {
$fieldValue = $value->color;
}
return "<div class='color small static'><div class='color-preview' style='background-color: {$fieldValue};'></div></div>";
// . "<div class='colorhex code'>{$value->label}</div>";

return '<div class="color small static"><div class="color-preview" style="'.$style.'"></div></div>';
}
}
42 changes: 42 additions & 0 deletions src/migrations/m200911_142127_update_namespace.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace percipioglobal\colourswatches\migrations;

use Craft;
use craft\db\Migration;

/**
* m200911_142127_update_namespace migration.
*/
class m200911_142127_update_namespace extends Migration
{
/**
* @inheritdoc
*/
public function safeUp()
{
echo "update_namespace updating .\n";

$this->update(
'{{%fields}}',
[
'type' => 'percipioglobal\\colourswatches\\fields\\ColourSwatches'
],
'type = :riastype',
[
':riastype' => 'rias\\colourswatches\\fields\\ColourSwatches'
]
);

return true;
}

/**
* @inheritdoc
*/
public function safeDown()
{
echo "m200911_142127_update_namespace cannot be reverted.\n";
return false;
}
}
Loading