Skip to content

Commit daf2ff3

Browse files
committed
RINGSTED-648 fix color php8 compatibility
1 parent 9fc1da3 commit daf2ff3

File tree

3 files changed

+124
-2
lines changed

3 files changed

+124
-2
lines changed

composer.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"drupal/ckeditor_iframe": "^2.1",
5757
"drupal/ckeditor_resize": "^1.3",
5858
"drupal/coder": "^8.3",
59+
"drupal/color": "^1.0",
5960
"drupal/config_delete": "^1.17",
6061
"drupal/console": "^1.0.2",
6162
"drupal/content_access": "^1.0",
@@ -221,7 +222,11 @@
221222
},
222223
"drupal/facets" : {
223224
"Add option to reset other facets on value change" : "https://www.drupal.org/files/issues/2023-01-25/3190289-22-reroll.patch"
224-
}
225+
},
226+
"drupal/color" : {
227+
"fix color php8 issues " : "./patches/20230320-color-php8.patch"
228+
}
229+
225230
}
226231
}
227232
}

composer.lock

Lines changed: 52 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

patches/20230320-color-php8.patch

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
diff --git a/color.module b/color.module
2+
index 8a8aa5e..2a1c638 100644
3+
--- a/color.module
4+
+++ b/color.module
5+
@@ -543,7 +543,7 @@ function _color_rewrite_stylesheet($theme, &$info, &$paths, $palette, $style) {
6+
}
7+
// Not a pre-set color. Extrapolate from the base.
8+
else {
9+
- $chunk = _color_shift($palette[$base], $default[$base], $chunk, $info['blend_target']);
10+
+ $chunk = _color_shift(($palette[$base] ?? 0), ($default[$base] ?? 0), ($chunk ?? 0), ($info['blend_target'] ?? 0)) ;
11+
}
12+
}
13+
else {
14+
@@ -695,14 +695,14 @@ function _color_shift($given, $ref1, $ref2, $target) {
15+
$numerator = 0;
16+
$denominator = 0;
17+
for ($i = 0; $i < 3; ++$i) {
18+
- $numerator += ($ref2[$i] - $ref1[$i]) * ($ref2[$i] - $ref1[$i]);
19+
- $denominator += ($target[$i] - $ref1[$i]) * ($target[$i] - $ref1[$i]);
20+
+ $numerator += (($ref2[$i] ?? 0) - ($ref1[$i] ?? 0)) * (($ref2[$i] ?? 0) - ($ref1[$i] ?? 0));
21+
+ $denominator += (($target[$i] ?? 0) - ($ref1[$i] ?? 0)) * (($target[$i] ?? 0) - ($ref1[$i] ?? 0));
22+
}
23+
$delta = ($denominator > 0) ? (1 - sqrt($numerator / $denominator)) : 0;
24+
25+
// Calculate the color that ref2 would be if the assumption was true.
26+
for ($i = 0; $i < 3; ++$i) {
27+
- $ref3[$i] = $target[$i] + ($ref1[$i] - $target[$i]) * $delta;
28+
+ $ref3[$i] = ($target[$i] ?? 0) + (($ref1[$i] ?? 0) - ($target[$i] ??0)) * ($delta ?? 0);
29+
}
30+
31+
// If the assumption is not true, there is a difference between ref2 and ref3.
32+
@@ -716,7 +716,7 @@ function _color_shift($given, $ref1, $ref2, $target) {
33+
// Take the given color, and blend it towards the target.
34+
$given = _color_unpack($given, TRUE);
35+
for ($i = 0; $i < 3; ++$i) {
36+
- $result[$i] = $target[$i] + ($given[$i] - $target[$i]) * $delta;
37+
+ $result[$i] = ($target[$i] ?? 0) + (($given[$i] ?? 0) - ($target[$i] ?? 0)) * ($delta ?? 0);
38+
}
39+
40+
// Finally, we apply the extra shift in HSL space.
41+
@@ -757,15 +757,17 @@ function _color_blend($img, $hex1, $hex2, $alpha) {
42+
* Converts a hex color into an RGB triplet.
43+
*/
44+
function _color_unpack($hex, $normalize = FALSE) {
45+
- $hex = substr($hex, 1);
46+
- if (strlen($hex) == 3) {
47+
- $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2];
48+
- }
49+
- $c = hexdec($hex);
50+
- for ($i = 16; $i >= 0; $i -= 8) {
51+
- $out[] = (($c >> $i) & 0xFF) / ($normalize ? 255 : 1);
52+
+ $out = array();
53+
+ if (!empty($hex)) {
54+
+ $hex = substr($hex, 1);
55+
+ if (strlen($hex) == 3) {
56+
+ $hex = ($hex[0] ?? 0) . ($hex[0] ?? 0) . ($hex[1] ?? 0) . ($hex[1] ?? 0). ($hex[2] ?? 0) . ($hex[2] ?? 0);
57+
+ }
58+
+ $c = hexdec($hex);
59+
+ for ($i = 16; $i >= 0; $i -= 8) {
60+
+ $out[] = (($c >> $i) & 0xFF) / ($normalize ? 255 : 1);
61+
+ }
62+
}
63+
-
64+
return $out;
65+
}
66+

0 commit comments

Comments
 (0)