diff --git a/color_field.module b/color_field.module index 160606c..6bb7368 100644 --- a/color_field.module +++ b/color_field.module @@ -1,4 +1,5 @@ array( - 'shape' => NULL, - 'color' => NULL, - 'width' => NULL, - 'height' => NULL, - ), + 'variables' => array( + 'shape' => NULL, + 'color' => NULL, + 'width' => NULL, + 'height' => NULL, + ), ); $theme['color_field_widget_box'] = array( @@ -76,7 +77,6 @@ function color_field_theme() { function template_preprocess_color_field_formatter_swatch(&$variables) { } - /** * Prepares variables for color_field widget box wrapper template. * diff --git a/css/color_field_formatter_swatch.css b/css/color_field_formatter_swatch.css index d66866d..c839284 100644 --- a/css/color_field_formatter_swatch.css +++ b/css/color_field_formatter_swatch.css @@ -1,5 +1,7 @@ -.color_field {} -.color_field__swatch {} +.color_field { +} +.color_field__swatch { +} .color_field__swatch--square { } .color_field__swatch--circle { diff --git a/css/color_field_widget_grid.css b/css/color_field_widget_grid.css index 1f1acb5..be1f2d3 100644 --- a/css/color_field_widget_grid.css +++ b/css/color_field_widget_grid.css @@ -9,4 +9,3 @@ .simpleColorChooser { z-index: 1; } - diff --git a/js/color_field_widget_box.jquery.js b/js/color_field_widget_box.jquery.js index 23bef75..c9e1a9a 100644 --- a/js/color_field_widget_box.jquery.js +++ b/js/color_field_widget_box.jquery.js @@ -30,7 +30,7 @@ colors: default_colors, blotchClass:'color_field_widget_box__square', blotchTransparentClass:'color_field_widget_box__square--transparent', - clickCallback: function(color) { + clickCallback: function (color) { $input.val(color).trigger('change'); } }); diff --git a/js/color_field_widget_box.js b/js/color_field_widget_box.js index 5839993..ef267b0 100644 --- a/js/color_field_widget_box.js +++ b/js/color_field_widget_box.js @@ -1,16 +1,22 @@ /** - * Color Field jQuery + * @file + * Color Field jQuery. */ + (function ($) { + jQuery.fn.addColorPicker = function (props) { - if (!props) { props = []; } + + if (!props) { + props = []; + } props = jQuery.extend({ currentColor:'', blotchElemType: 'span', blotchClass:'colorBox', blotchTransparentClass:'transparentBox', - clickCallback: function(ignoredColor) {}, + clickCallback: function (ignoredColor) {}, iterationCallback: null, fillString: ' ', fillStringX: '?', @@ -30,12 +36,12 @@ jQuery.fn.addColorPicker = function (props) { .addClass(props.blotchClass) .attr('color',color) .css('background-color',color); - // jq bug: chaining here fails if color is null b/c .css() returns (new String('transparent'))! + // Jq bug: chaining here fails if color is null b/c .css() returns (new String('transparent'))! if (props.currentColor == color) { elem.addClass('active'); } if (props.clickCallback) { - elem.click(function() { + elem.click(function () { jQuery(this).parent().children('.' + props.blotchClass).removeClass('active'); jQuery(this).addClass('active'); props.clickCallback(jQuery(this).attr('color')); @@ -57,7 +63,7 @@ jQuery.fn.addColorPicker = function (props) { } if (props.clickCallback) { - elem.click(function() { + elem.click(function () { jQuery(this).parent().children('.' + props.blotchClass).removeClass('active'); jQuery(this).addClass('active'); props.clickCallback(jQuery(this).attr('color')); diff --git a/js/color_field_widget_grid.jquery.js b/js/color_field_widget_grid.jquery.js index 6421572..1c5521c 100644 --- a/js/color_field_widget_grid.jquery.js +++ b/js/color_field_widget_grid.jquery.js @@ -2,6 +2,7 @@ * @file * Javascript for Color Field. */ + (function ($, Drupal) { 'use strict'; diff --git a/js/color_field_widget_spectrum.jquery.js b/js/color_field_widget_spectrum.jquery.js index 335103e..459846f 100644 --- a/js/color_field_widget_spectrum.jquery.js +++ b/js/color_field_widget_spectrum.jquery.js @@ -2,6 +2,7 @@ * @file * Javascript for Color Field. */ + (function ($, Drupal) { 'use strict'; @@ -37,7 +38,7 @@ showButtons: spectrum_settings.show_buttons, allowEmpty: spectrum_settings.allow_empty, - change: function(tinycolor) { + change: function (tinycolor) { $element_color.val(tinycolor.toHexString()); $element_opacity.val(tinycolor._roundA); } diff --git a/src/ColorCMY.php b/src/ColorCMY.php index 796952b..febca7d 100644 --- a/src/ColorCMY.php +++ b/src/ColorCMY.php @@ -8,34 +8,37 @@ namespace Drupal\color_field; class ColorCMY extends ColorBase { /** - * The cyan + * The cyan. + * * @var float */ private $cyan; /** - * The magenta + * The magenta. + * * @var float */ private $magenta; /** - * The yellow + * The yellow. + * * @var float */ private $yellow; /** - * Create a new CMYK color + * Create a new CMYK color. * * @param float $cyan - * The cyan + * The cyan. * @param float $magenta - * The magenta + * The magenta. * @param float $yellow - * The yellow + * The yellow. * @param float $opacity - * The opacity + * The opacity. */ public function __construct($cyan, $magenta, $yellow, $opacity) { $this->cyan = $cyan; @@ -45,40 +48,43 @@ class ColorCMY extends ColorBase { } /** - * Get the amount of Cyan + * Get the amount of Cyan. * - * @return int The amount of cyan + * @return int + * The amount of cyan. */ public function getCyan() { return $this->cyan; } /** - * Get the amount of Magenta + * Get the amount of Magenta. * - * @return int The amount of magenta + * @return int + * The amount of magenta. */ public function getMagenta() { return $this->magenta; } /** - * Get the amount of Yellow + * Get the amount of Yellow. * - * @return int The amount of yellow + * @return int + * The amount of yellow. */ public function getYellow() { return $this->yellow; } /** - * A string representation of this color in the current format + * A string representation of this color in the current format. * * @param bool $opacity * Whether or not to display the opacity. * * @return string - * The color in format: #RRGGBB + * The color in format: #RRGGBB. */ public function toString($opacity = TRUE) { } diff --git a/src/ColorCMYK.php b/src/ColorCMYK.php index a2e2cbc..fc16a72 100644 --- a/src/ColorCMYK.php +++ b/src/ColorCMYK.php @@ -8,38 +8,46 @@ namespace Drupal\color_field; class ColorCMYK extends ColorBase { /** - * The cyan + * The cyan. + * * @var float */ private $cyan; /** - * The magenta + * The magenta. + * * @var float */ private $magenta; /** - * The yellow + * The yellow. + * * @var float */ private $yellow; /** - * The key (black) + * The key (black). + * * @var float */ private $key; /** - * Create a new CMYK color + * Create a new CMYK color. * - * @param float $cyan The cyan - * @param float $magenta The magenta - * @param float $yellow The yellow - * @param float $key The key (black) + * @param float $cyan + * The cyan. + * @param float $magenta + * The magenta. + * @param float $yellow + * The yellow. + * @param float $key + * The key (black). * @param float $opacity - * The opacity + * The opacity. */ public function __construct($cyan, $magenta, $yellow, $key, $opacity) { $this->cyan = $cyan; @@ -50,49 +58,53 @@ class ColorCMYK extends ColorBase { } /** - * Get the amount of Cyan + * Get the amount of Cyan. * - * @return int The amount of cyan + * @return int + * The amount of cyan. */ public function getCyan() { return $this->cyan; } /** - * Get the amount of Magenta + * Get the amount of Magenta. * - * @return int The amount of magenta + * @return int + * The amount of magenta. */ public function getMagenta() { return $this->magenta; } /** - * Get the amount of Yellow + * Get the amount of Yellow. * - * @return int The amount of yellow + * @return int + * The amount of yellow. */ public function getYellow() { return $this->yellow; } /** - * Get the key (black) + * Get the key (black). * - * @return int The amount of black + * @return int + * The amount of black. */ public function getKey() { return $this->key; } /** - * A string representation of this color in the current format + * A string representation of this color in the current format. * * @param bool $opacity * Whether or not to display the opacity. * * @return string - * The color in format: #RRGGBB + * The color in format: #RRGGBB. */ public function toString($opacity = TRUE) { } diff --git a/src/ColorHex.php b/src/ColorHex.php index b19b911..6c8b891 100644 --- a/src/ColorHex.php +++ b/src/ColorHex.php @@ -3,12 +3,13 @@ namespace Drupal\color_field; /** - * Hex represents the Hex color format + * Hex represents the Hex color format. */ class ColorHex extends ColorBase { /** * The Hex triplet of the color. + * * @var int */ private $color; @@ -20,8 +21,7 @@ class ColorHex extends ColorBase { * The string hex value (i.e. "FFFFFF"). * @param string $opacity * The opacity value. - * @return ColorHex - * The ColorHex object. + * * @throws Exception */ public function __construct($color, $opacity) { @@ -46,13 +46,13 @@ class ColorHex extends ColorBase { } /** - * A string representation of this color in the current format + * A string representation of this color in the current format. * * @param bool $opacity * Whether or not to display the opacity. * * @return string - * The color in format: #RRGGBB + * The color in format: #RRGGBB. */ public function toString($opacity = TRUE) { $rgb = $this->toRGB(); diff --git a/src/ColorInterface.php b/src/ColorInterface.php index c7d755f..7ef799b 100644 --- a/src/ColorInterface.php +++ b/src/ColorInterface.php @@ -13,14 +13,9 @@ interface ColorInterface { public function toRGB(); - //public function toHSV(); - - //public function toHSL(); - - //public function toRGB(); - - //public function toCMYK(); - - //public function toCSS(); - + // public function toHSV(); + // public function toHSL(); + // public function toRGB(); + // public function toCMYK(); + // public function toCSS(); } diff --git a/src/ColorRGB.php b/src/ColorRGB.php index 77d138e..ec7ae7a 100644 --- a/src/ColorRGB.php +++ b/src/ColorRGB.php @@ -3,30 +3,33 @@ namespace Drupal\color_field; /** - * RGB represents the RGB color format + * RGB represents the RGB color format. */ class ColorRGB extends ColorBase { /** - * The red value (0-255) + * The red value (0-255). + * * @var float */ private $red; /** - * The green value (0-255) + * The green value (0-255). + * * @var float */ private $green; /** - * The blue value (0-255) + * The blue value (0-255). + * * @var float */ private $blue; /** - * Create a new RGB color + * Create a new RGB color. * * @param int $red * The red (0-255) @@ -35,7 +38,7 @@ class ColorRGB extends ColorBase { * @param int $blue * The blue (0-255) * @param float $opacity - * The opacity + * The opacity. * * @throws Exception */ @@ -58,34 +61,37 @@ class ColorRGB extends ColorBase { } /** - * Get the red value (rounded) + * Get the red value (rounded). * - * @return int The red value + * @return int + * The red value */ public function getRed() { return (0.5 + $this->red) | 0; } /** - * Get the green value (rounded) + * Get the green value (rounded). * - * @return int The green value + * @return int + * The green value */ public function getGreen() { return (0.5 + $this->green) | 0; } /** - * Get the blue value (rounded) + * Get the blue value (rounded). * - * @return int The blue value + * @return int + * The blue value */ public function getBlue() { return (0.5 + $this->blue) | 0; } /** - * A string representation of this color in the current format + * A string representation of this color in the current format. * * @param bool $opacity * Whether or not to display the opacity. diff --git a/src/Plugin/Field/FieldFormatter/ColorFieldFormatterCss.php b/src/Plugin/Field/FieldFormatter/ColorFieldFormatterCss.php index 585b192..38e0c1c 100644 --- a/src/Plugin/Field/FieldFormatter/ColorFieldFormatterCss.php +++ b/src/Plugin/Field/FieldFormatter/ColorFieldFormatterCss.php @@ -1,10 +1,5 @@ TRUE, '#placeholder' => 'body > div > a', ); - //$element['token'] = array( - // '#theme' => 'token_tree', - // '#token_types' => array($instance['entity_type']), - // '#dialog' => TRUE, - //); + // $element['token'] = array( + // '#theme' => 'token_tree', + // '#token_types' => array($instance['entity_type']), + // '#dialog' => TRUE, + // ); . $elements['property'] = array( '#title' => t('Property'), - '#description' => t(''), + '#description' => '', '#type' => 'select', '#default_value' => $this->getSetting('property'), '#required' => TRUE, @@ -133,7 +128,8 @@ class ColorFieldFormatterCss extends FormatterBase { $elements['#attached']['html_head'][] = [[ '#tag' => 'style', '#value' => $inline_css, - ], 'colorfield_css']; + ], 'colorfield_css', + ]; } return $elements; @@ -150,7 +146,8 @@ class ColorFieldFormatterCss extends FormatterBase { if ($opacity && $settings['opacity']) { $rgbtext = $color_hex->toRGB()->toString(TRUE); - } else { + } + else { $rgbtext = $color_hex->toRGB()->toString(FALSE); } diff --git a/src/Plugin/Field/FieldFormatter/ColorFieldFormatterSwatch.php b/src/Plugin/Field/FieldFormatter/ColorFieldFormatterSwatch.php index 7b0b561..6ddeabc 100644 --- a/src/Plugin/Field/FieldFormatter/ColorFieldFormatterSwatch.php +++ b/src/Plugin/Field/FieldFormatter/ColorFieldFormatterSwatch.php @@ -1,10 +1,5 @@ t('Shape'), '#options' => $this->getShape(), '#default_value' => $this->getSetting('shape'), - '#description' => t(''), + '#description' => '', ); $elements['width'] = array( '#type' => 'number', '#title' => t('Width'), '#default_value' => $this->getSetting('width'), '#min' => 1, - '#description' => t(''), + '#description' => '', ); $elements['height'] = array( '#type' => 'number', '#title' => t('Height'), '#default_value' => $this->getSetting('height'), '#min' => 1, - '#description' => t(''), + '#description' => '', ); if ($opacity) { @@ -82,7 +77,10 @@ class ColorFieldFormatterSwatch extends FormatterBase { } /** + * This is used to get the shape. + * * @param string $shape + * * @return array|string */ protected function getShape($shape = NULL) { @@ -112,7 +110,7 @@ class ColorFieldFormatterSwatch extends FormatterBase { $summary[] = t('Width: @width Height: @height', array( '@width' => $settings['width'], - '@height' => $settings['height'] + '@height' => $settings['height'], )); if ($opacity && $settings['opacity']) { @@ -156,7 +154,8 @@ class ColorFieldFormatterSwatch extends FormatterBase { if ($opacity && $settings['opacity']) { $rgbtext = $color_hex->toRGB()->toString(TRUE); - } else { + } + else { $rgbtext = $color_hex->toRGB()->toString(FALSE); } diff --git a/src/Plugin/Field/FieldFormatter/ColorFieldFormatterText.php b/src/Plugin/Field/FieldFormatter/ColorFieldFormatterText.php index b6ef971..158b7a4 100644 --- a/src/Plugin/Field/FieldFormatter/ColorFieldFormatterText.php +++ b/src/Plugin/Field/FieldFormatter/ColorFieldFormatterText.php @@ -1,10 +1,5 @@ toString(TRUE); - } else { + } + else { $output = $color_hex->toString(FALSE); } break; @@ -132,7 +133,8 @@ class ColorFieldFormatterText extends FormatterBase { case 'rgb': if ($opacity && $settings['opacity']) { $output = $color_hex->toRGB()->toString(TRUE); - } else { + } + else { $output = $color_hex->toRGB()->toString(FALSE); } break; diff --git a/src/Plugin/Field/FieldType/ColorFieldType.php b/src/Plugin/Field/FieldType/ColorFieldType.php index db84a8e..dbda64d 100644 --- a/src/Plugin/Field/FieldType/ColorFieldType.php +++ b/src/Plugin/Field/FieldType/ColorFieldType.php @@ -1,10 +1,5 @@ getSetting('format'); - $color_length = isset($format) ? strlen($format) : 7 ; + $color_length = isset($format) ? strlen($format) : 7; return array( 'columns' => array( 'color' => array( @@ -148,7 +143,7 @@ class ColorFieldType extends FieldItemBase { 'color' => array( 'Regex' => array( 'pattern' => '/^#?(([0-9a-fA-F]{2}){3}|([0-9a-fA-F]){3})$/i', - ) + ), ), )); @@ -159,7 +154,7 @@ class ColorFieldType extends FieldItemBase { 'Range' => array( 'min' => $min, 'minMessage' => t('%name: the opacity may be no less than %min.', array('%name' => $label, '%min' => $min)), - ) + ), ), )); @@ -169,7 +164,7 @@ class ColorFieldType extends FieldItemBase { 'Range' => array( 'max' => $max, 'maxMessage' => t('%name: the opacity may be no greater than %max.', array('%name' => $label, '%max' => $max)), - ) + ), ), )); } @@ -188,12 +183,15 @@ class ColorFieldType extends FieldItemBase { case '#HEXHEX': $values['color'] = '#111AAA'; break; + case 'HEXHEX': $values['color'] = '111111'; break; + case '#hexhex': $values['color'] = '#111aaa'; break; + case 'hexhex': $values['color'] = '111111'; break; @@ -225,12 +223,15 @@ class ColorFieldType extends FieldItemBase { case '#HEXHEX': $color = '#' . strtoupper($color); break; + case 'HEXHEX': $color = strtoupper($color); break; + case '#hexhex': $color = '#' . strtolower($color); break; + case 'hexhex': $color = strtolower($color); break; diff --git a/src/Plugin/Field/FieldWidget/ColorFieldWidgetBox.php b/src/Plugin/Field/FieldWidget/ColorFieldWidgetBox.php index 8268704..1d8bfa9 100644 --- a/src/Plugin/Field/FieldWidget/ColorFieldWidgetBox.php +++ b/src/Plugin/Field/FieldWidget/ColorFieldWidgetBox.php @@ -1,10 +1,5 @@ 'textfield', '#default_value' => $color, '#attributes' => array('class' => array('visually-hidden')), - ); + ); $element['color']['#suffix'] = "
"; if ($this->getFieldSetting('opacity')) { diff --git a/src/Plugin/Field/FieldWidget/ColorFieldWidgetDefault.php b/src/Plugin/Field/FieldWidget/ColorFieldWidgetDefault.php index d0bc375..5905bc1 100644 --- a/src/Plugin/Field/FieldWidget/ColorFieldWidgetDefault.php +++ b/src/Plugin/Field/FieldWidget/ColorFieldWidgetDefault.php @@ -1,10 +1,5 @@ fieldDefinition->getLabel(); $element['color'] = array( - '#title' => t($label), + '#title' => $label, '#type' => 'textfield', '#maxlength' => 7, '#size' => 7, diff --git a/src/Plugin/Field/FieldWidget/ColorFieldWidgetGrid.php b/src/Plugin/Field/FieldWidget/ColorFieldWidgetGrid.php index dda5b12..1eed077 100644 --- a/src/Plugin/Field/FieldWidget/ColorFieldWidgetGrid.php +++ b/src/Plugin/Field/FieldWidget/ColorFieldWidgetGrid.php @@ -1,10 +1,5 @@