Skip to content

Commit 25d4767

Browse files
feat: support rockpagebuilder HTML labels
1 parent 3e4332f commit 25d4767

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

InputfieldMarkup.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,10 @@
22
<?php
33
foreach ($f->colors() as $col) {
44
$selected = ($value == $col->name) ? "selected" : "";
5-
6-
// prepare html and style tag
7-
// If provided a color like #ff0000 or rgba(0,0,0) we prepend the
8-
// background-color property. Otherwise we use it as is.
9-
$style = $col->css;
10-
if (strpos($style, "<") === 0) {
11-
$html = $style;
5+
if (strpos($col->css, "<") === 0) {
6+
$html = $col->css;
127
} else {
13-
if (!strpos($style, ":")) $style = "background-color:$style";
14-
$html = "<div style='$style'></div>";
8+
$html = "<div style='{$col->style}'></div>";
159
}
1610

1711
// output wrapper + html

RockColorPicker.module.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public static function getModuleInfo()
1818
{
1919
return [
2020
'title' => 'RockColorPicker',
21-
'version' => '1.1.0',
21+
'version' => '1.2.0',
2222
'summary' => 'Main RockColorPicker Module',
2323
'autoload' => false,
2424
'singular' => true, // sic
@@ -47,6 +47,20 @@ public function ___colors()
4747
return $this->colors;
4848
}
4949

50+
/**
51+
* Return style string from css setting
52+
* If provided a color like #ff0000 or rgba(0,0,0) we prepend the
53+
* background-color property. Otherwise we use it as is.
54+
* css = #afafaf --> style = background-color:#afafaf;
55+
* css = 'foo:bar' --> style = 'foo:bar'
56+
*/
57+
public function getStyle($item): string
58+
{
59+
$style = $item->css;
60+
if (!strpos($style, ":")) $style = "background-color:$style";
61+
return $style;
62+
}
63+
5064
public function loadAssets()
5165
{
5266
if ($this->assetsAdded) return;
@@ -73,6 +87,7 @@ public function setColors($field, $colors, $force = false)
7387
$item = $this->wire(new WireData());
7488
$item->name = $name;
7589
$item->css = $data[0];
90+
$item->style = $this->getStyle($item);
7691
$item->label = count($data) > 1 ? $data[1] : '';
7792
$arr->set($name, $item);
7893
}

0 commit comments

Comments
 (0)