Skip to content

Commit

Permalink
Merge branch 'craft-3' of https://github.com/verbb/buttonbox into cra…
Browse files Browse the repository at this point in the history
…ft-4

# Conflicts:
#	CHANGELOG.md
#	composer.json
#	src/fields/Buttons.php
#	src/fields/Colours.php
#	src/fields/Stars.php
#	src/fields/TextSize.php
#	src/fields/Triggers.php
#	src/fields/Width.php
#	src/migrations/m190506_031734_migrate_buttonbox.php
#	src/resources/dist/css/buttonbox.css
  • Loading branch information
engram-design committed Jun 28, 2022
2 parents 41a2ff1 + 3d40d59 commit e5d00ba
Show file tree
Hide file tree
Showing 16 changed files with 63 additions and 72 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Expand Up @@ -32,6 +32,16 @@
- Now requires PHP `8.0.2+`.
- Now requires Craft `4.0.0+`.


## 3.1.0 - 2022-06-29

### Changed
- Now requires Craft 3.7.46+.

### Fixed
- Fix a type error occurring on Craft 3.7.46.
- Fix colour field default value not being set correctly.

## 3.0.2 - 2022-06-21

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2022 Verbb
Copyright (c) 2022 Verbb, 2018 Supercool Ltd

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
8 changes: 8 additions & 0 deletions config.codekit3
Expand Up @@ -301,6 +301,14 @@
"oA" : 1,
"oAP" : "\/src\/templates",
"oF" : 0
},
"\/src\/translations\/en\/buttonbox.php" : {
"cB" : 0,
"ft" : 8192,
"hM" : 0,
"oA" : 2,
"oAP" : "\/src\/translations\/en\/buttonbox.php",
"oF" : 0
}
},
"hooks" : [
Expand Down
7 changes: 3 additions & 4 deletions src/ButtonBox.php
Expand Up @@ -9,7 +9,6 @@
use verbb\buttonbox\fields\Width as WidthField;
use verbb\buttonbox\fields\Triggers as TriggersField;

use Craft;
use craft\base\Plugin;
use craft\events\RegisterComponentTypesEvent;
use craft\services\Fields;
Expand All @@ -34,7 +33,7 @@ class ButtonBox extends Plugin
// Public Methods
// =========================================================================

public function init()
public function init(): void
{
parent::init();

Expand All @@ -48,8 +47,8 @@ public function init()

// Private Methods
// =========================================================================
private function _registerFieldTypes()

private function _registerFieldTypes(): void
{
Event::on(Fields::class, Fields::EVENT_REGISTER_FIELD_TYPES, function(RegisterComponentTypesEvent $event) {
$event->types[] = StarsField::class;
Expand Down
3 changes: 1 addition & 2 deletions src/assetbundles/ButtonBoxAsset.php
@@ -1,7 +1,6 @@
<?php
namespace verbb\buttonbox\assetbundles;

use Craft;
use craft\web\AssetBundle;
use craft\web\assets\cp\CpAsset;

Expand All @@ -12,7 +11,7 @@ class ButtonBoxAsset extends AssetBundle
// Public Methods
// =========================================================================

public function init()
public function init(): void
{
$this->sourcePath = "@verbb/buttonbox/resources/dist";

Expand Down
4 changes: 2 additions & 2 deletions src/base/PluginTrait.php
Expand Up @@ -42,12 +42,12 @@ public static function error($message, $attributes = []): void
// Private Methods
// =========================================================================

private function _setPluginComponents()
private function _setPluginComponents(): void
{
BaseHelper::registerModule();
}

private function _setLogging()
private function _setLogging(): void
{
BaseHelper::setFileLogging('buttonbox');
}
Expand Down
20 changes: 8 additions & 12 deletions src/fields/Buttons.php
Expand Up @@ -8,10 +8,6 @@
use craft\fields\BaseOptionsField;
use craft\fields\data\OptionData;
use craft\fields\data\SingleOptionFieldData;
use craft\helpers\Cp;
use craft\helpers\Db;
use craft\helpers\Json;
use craft\helpers\Template;
use craft\helpers\UrlHelper;

use yii\db\Schema;
Expand All @@ -20,7 +16,7 @@ class Buttons extends BaseOptionsField
{
// Static Methods
// =========================================================================

public static function displayName(): string
{
return Craft::t('buttonbox', 'Button Box - Buttons');
Expand Down Expand Up @@ -48,7 +44,7 @@ public function normalizeValue(mixed $value, ElementInterface $element = null):
if (!$value) {
$value = $this->defaultValue();
}

if ($value instanceof SingleOptionFieldData) {
$value = $value->value;
}
Expand Down Expand Up @@ -80,10 +76,10 @@ public function getSettingsHtml(): ?string
if (!$options) {
$options = [
[
'label' => '',
'showLabel' => false,
'value' => '',
'imageUrl' => '',
'label' => '',
'showLabel' => false,
'value' => '',
'imageUrl' => '',
],
];
}
Expand Down Expand Up @@ -177,8 +173,8 @@ public function getInputHtml(mixed $value, ElementInterface $element = null): st

// Protected Methods
// =========================================================================
protected function optionsSettingLabel() : string

protected function optionsSettingLabel(): string
{
return Craft::t('buttonbox', 'Button Options');
}
Expand Down
16 changes: 6 additions & 10 deletions src/fields/Colours.php
Expand Up @@ -8,18 +8,14 @@
use craft\fields\BaseOptionsField;
use craft\fields\data\OptionData;
use craft\fields\data\SingleOptionFieldData;
use craft\helpers\Cp;
use craft\helpers\Db;
use craft\helpers\Json;
use craft\helpers\Template;

use yii\db\Schema;

class Colours extends BaseOptionsField
{
// Static Methods
// =========================================================================

public static function displayName(): string
{
return Craft::t('buttonbox', 'Button Box - Colours');
Expand All @@ -40,12 +36,12 @@ public function getContentColumnType(): string
return Schema::TYPE_TEXT;
}

public function normalizeValue(mixed $value, ElementInterface $element = null): mixed
public function normalizeValue($value, ElementInterface $element = null): SingleOptionFieldData
{
if (!$value) {
$value = $this->defaultValue();
}

if ($value instanceof SingleOptionFieldData) {
$value = $value->value;
}
Expand Down Expand Up @@ -142,8 +138,8 @@ public function getInputHtml(mixed $value, ElementInterface $element = null): st

// Protected Methods
// =========================================================================
protected function optionsSettingLabel() : string

protected function optionsSettingLabel(): string
{
return Craft::t('buttonbox', 'Colour Options');
}
Expand All @@ -166,7 +162,7 @@ protected function translatedOptions(bool $encode = false): array
$translatedOptions = [];

foreach ($this->options as $option) {
$cssColour = !strstr($option['cssColour'], '#') ? '#' . $option['cssColour'] : $option['cssColour'];
$cssColour = strpos($option['cssColour'], '#') === false ? '#' . $option['cssColour'] : $option['cssColour'];

$translatedOptions[] = [
'label' => Craft::t('site', $option['label']),
Expand Down
13 changes: 4 additions & 9 deletions src/fields/Stars.php
Expand Up @@ -6,9 +6,6 @@
use Craft;
use craft\base\ElementInterface;
use craft\base\Field;
use craft\helpers\Db;
use craft\helpers\Json;
use craft\helpers\Template;

use yii\db\Schema;

Expand All @@ -32,14 +29,12 @@ public static function displayName(): string
// Public Methods
// =========================================================================

public function rules(): array
public function defineRules(): array
{
$rules = parent::rules();
$rules = parent::defineRules();

$rules = array_merge($rules, [
['totalStars', 'required'],
['totalStars', 'integer', 'min' => 2],
]);
$rules[] = [['totalStars'], 'required'];
$rules[] = [['totalStars'], 'integer', 'min' => 2];

return $rules;
}
Expand Down
11 changes: 3 additions & 8 deletions src/fields/TextSize.php
Expand Up @@ -8,10 +8,6 @@
use craft\fields\BaseOptionsField;
use craft\fields\data\OptionData;
use craft\fields\data\SingleOptionFieldData;
use craft\helpers\Cp;
use craft\helpers\Db;
use craft\helpers\Json;
use craft\helpers\Template;

use yii\db\Schema;

Expand Down Expand Up @@ -45,7 +41,7 @@ public function normalizeValue(mixed $value, ElementInterface $element = null):
if (!$value) {
$value = $this->defaultValue();
}

if ($value instanceof SingleOptionFieldData) {
$value = $value->value;
}
Expand Down Expand Up @@ -137,14 +133,13 @@ public function getInputHtml(mixed $value, ElementInterface $element = null): st
'value' => $value,
'options' => $options,
]);

}


// Protected Methods
// =========================================================================
protected function optionsSettingLabel() : string

protected function optionsSettingLabel(): string
{
return Craft::t('buttonbox', 'Text Size Options');
}
Expand Down
12 changes: 3 additions & 9 deletions src/fields/Triggers.php
Expand Up @@ -6,19 +6,13 @@
use Craft;
use craft\base\ElementInterface;
use craft\fields\BaseOptionsField;
use craft\helpers\Cp;
use craft\helpers\Db;
use craft\helpers\Json;
use craft\helpers\Template;
use craft\helpers\UrlHelper;

use yii\db\Schema;

class Triggers extends BaseOptionsField
{
// Static Methods
// =========================================================================

public static function displayName(): string
{
return Craft::t('buttonbox', 'Button Box - Triggers');
Expand Down Expand Up @@ -160,8 +154,8 @@ public function getInputHtml(mixed $value, ElementInterface $element = null): st

// Protected Methods
// =========================================================================
protected function optionsSettingLabel() : string

protected function optionsSettingLabel(): string
{
return Craft::t('buttonbox', 'Triggers Options');
}
Expand Down
13 changes: 4 additions & 9 deletions src/fields/Width.php
Expand Up @@ -8,18 +8,14 @@
use craft\fields\BaseOptionsField;
use craft\fields\data\OptionData;
use craft\fields\data\SingleOptionFieldData;
use craft\helpers\Cp;
use craft\helpers\Db;
use craft\helpers\Json;
use craft\helpers\Template;

use yii\db\Schema;

class Width extends BaseOptionsField
{
// Static Methods
// =========================================================================

public static function displayName(): string
{
return Craft::t('buttonbox', 'Button Box - Width');
Expand All @@ -45,7 +41,7 @@ public function normalizeValue(mixed $value, ElementInterface $element = null):
if (!$value) {
$value = $this->defaultValue();
}

if ($value instanceof SingleOptionFieldData) {
$value = $value->value;
}
Expand Down Expand Up @@ -132,14 +128,13 @@ public function getInputHtml(mixed $value, ElementInterface $element = null): st
'value' => $value,
'options' => $options,
]);

}


// Protected Methods
// =========================================================================
protected function optionsSettingLabel() : string

protected function optionsSettingLabel(): string
{
return Craft::t('buttonbox', 'Width Options');
}
Expand Down
4 changes: 2 additions & 2 deletions src/migrations/m220604_000000_verbb_migration.php
Expand Up @@ -16,7 +16,7 @@ class m220604_000000_verbb_migration extends Migration
// Public Methods
// =========================================================================

public function safeUp()
public function safeUp(): bool
{
$this->update('{{%fields}}', ['type' => Buttons::class], ['type' => 'supercool\buttonbox\fields\Buttons']);
$this->update('{{%fields}}', ['type' => Colours::class], ['type' => 'supercool\buttonbox\fields\Colours']);
Expand Down Expand Up @@ -57,7 +57,7 @@ public function safeUp()
return true;
}

public function safeDown()
public function safeDown(): bool
{
echo "m220604_000000_verbb_migration cannot be reverted.\n";
return false;
Expand Down
6 changes: 2 additions & 4 deletions src/resources/src/scss/buttonbox.scss
Expand Up @@ -193,14 +193,12 @@
}

.buttonbox-width .btn.active {
background: #5286d9 !important;
background-image: linear-gradient(#659cdc, #5286d9) !important;
background: #5286d9 linear-gradient(#659cdc, #5286d9) !important;
border-color: #5286d9 !important;
}

.buttonbox-width .btn.hover {
background: #3c6da5 !important;
background-image: linear-gradient(#578dbc, #3c6da5) !important;
background: #3c6da5 linear-gradient(#578dbc, #3c6da5) !important;
border-color: #3c6da5 !important;
}

Expand Down
1 change: 1 addition & 0 deletions src/templates/_field/buttons/input.html
Expand Up @@ -34,6 +34,7 @@
<img {{ attr({
src: option.imageUrl,
title: not option.showLabel ? optionLabel : false,
alt: not option.showLabel ? optionLabel : false,
class: [
option.showLabel ? 'buttonbox-buttons__with-label' : false,
] | filter,
Expand Down

0 comments on commit e5d00ba

Please sign in to comment.