Created
October 12, 2017 09:08
-
-
Save IT-Cru/764f98e573b62d8569b73ef9bae25149 to your computer and use it in GitHub Desktop.
drupal/color_field: Fixes missing import declaration and some bad UI stuff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/Plugin/Field/FieldFormatter/ColorFieldFormatterCss.php b/src/Plugin/Field/FieldFormatter/ColorFieldFormatterCss.php | |
index 053191a..f55e24d 100644 | |
--- a/src/Plugin/Field/FieldFormatter/ColorFieldFormatterCss.php | |
+++ b/src/Plugin/Field/FieldFormatter/ColorFieldFormatterCss.php | |
@@ -8,6 +8,7 @@ | |
namespace Drupal\color_field\Plugin\Field\FieldFormatter; | |
use Drupal\Core\Field\FormatterBase; | |
+use Drupal\Core\Field\FieldItemInterface; | |
use Drupal\Core\Field\FieldItemListInterface; | |
use Drupal\Core\Form\FormStateInterface; | |
use Drupal\color_field\ColorHex; | |
@@ -69,6 +70,7 @@ class ColorFieldFormatterCss extends FormatterBase { | |
'#options' => array( | |
'background-color' => t('Background color'), | |
'color' => t('Text color'), | |
+ 'fill' => t('Fill color (SVG only)'), | |
), | |
); | |
$elements['important'] = array( | |
diff --git a/src/Plugin/Field/FieldWidget/ColorFieldWidgetHTML5.php b/src/Plugin/Field/FieldWidget/ColorFieldWidgetHTML5.php | |
index bb39cef..6d73a3a 100644 | |
--- a/src/Plugin/Field/FieldWidget/ColorFieldWidgetHTML5.php | |
+++ b/src/Plugin/Field/FieldWidget/ColorFieldWidgetHTML5.php | |
@@ -64,27 +64,42 @@ class ColorFieldWidgetHTML5 extends WidgetBase { | |
} | |
} | |
- $element['color'] = array( | |
- '#title' => t('Color'), | |
- '#type' => 'color', | |
- '#maxlength' => 7, | |
- '#size' => 7, | |
- '#required' => $element['#required'], | |
- '#default_value' => $color, | |
- ); | |
- | |
if ($this->getFieldSetting('opacity')) { | |
- $element['color']['#prefix'] = '<div class="container-inline">'; | |
- $element['opacity'] = array( | |
+ $details = [ | |
+ '#type' => 'details', | |
+ '#open' => TRUE, | |
+ ] + $element; | |
+ | |
+ $details['color'] = [ | |
+ '#prefix' => '<div class="container-inline">', | |
+ '#title' => t('Color'), | |
+ '#type' => 'color', | |
+ '#maxlength' => 7, | |
+ '#size' => 7, | |
+ '#required' => $element['#required'], | |
+ '#default_value' => $color, | |
+ ]; | |
+ | |
+ $details['opacity'] = [ | |
+ '#suffix' => '</div>', | |
'#title' => t('Opacity'), | |
'#type' => 'textfield', | |
'#maxlength' => 4, | |
'#size' => 4, | |
'#required' => $element['#required'], | |
'#default_value' => isset($items[$delta]->opacity) ? $items[$delta]->opacity : NULL, | |
- '#suffix' => '</div>', | |
- ); | |
+ ]; | |
+ | |
+ $element = $details; | |
+ | |
+ } else { | |
+ $element['color'] = [ | |
+ '#type' => 'color', | |
+ '#maxlength' => 7, | |
+ '#size' => 7, | |
+ '#default_value' => $color, | |
+ ] + $element; | |
} | |
return $element; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment