mirror of
https://github.com/processwire/processwire.git
synced 2025-08-09 16:26:59 +02:00
Add support for specifying a background color for repeater items by type. This is likely only useful in RepeaterMatrix but had to be added to the core repeater to support. The way you define it is by specifying a color hex code like #999999 or #999 somewhere in the repeater item type label (I suggest at the end). The color hex code will be removed from the label automatically and used to change its background color. Note that the text color is white, so use only background colors that would work with white text.
This commit is contained in:
@@ -327,6 +327,7 @@ class InputfieldRepeater extends Inputfield implements InputfieldItemList {
|
||||
$input = $this->wire()->input;
|
||||
$session = $this->wire()->session;
|
||||
$modules = $this->wire()->modules;
|
||||
$typeStyles = array();
|
||||
|
||||
// if it's already been built, then return the cached version
|
||||
if(!is_null($this->form)) return $this->form;
|
||||
@@ -460,6 +461,10 @@ class InputfieldRepeater extends Inputfield implements InputfieldItemList {
|
||||
$wrapIcon = '';
|
||||
$wrapClasses = array_unique(array('InputfieldRepeaterItem', $this->className() . 'Item', 'InputfieldNoFocus'));
|
||||
$wrap->addClass(implode(' ', $wrapClasses));
|
||||
|
||||
$itemType = $this->getRepeaterItemType($page);
|
||||
$itemTypeName = $this->getRepeaterItemTypeName($itemType);
|
||||
|
||||
if(!$isPost) {
|
||||
$wrap->entityEncodeLabel = false;
|
||||
$wrapLabel =
|
||||
@@ -470,12 +475,21 @@ class InputfieldRepeater extends Inputfield implements InputfieldItemList {
|
||||
$wrapLabel = str_replace($matches[0], '', $wrapLabel);
|
||||
$wrapIcon = $matches[1];
|
||||
}
|
||||
if(strpos($wrapLabel, '#') !== false && preg_match('/#([0-9a-fA-F]{3,})/', $wrapLabel, $matches)) {
|
||||
// background-color definition
|
||||
if(strlen($matches[1]) === 3 || strlen($matches[1]) === 6) {
|
||||
$wrapLabel = str_replace($matches[0], '', $wrapLabel);
|
||||
$typeStyles[] =
|
||||
".Inputfield_$this->name .InputfieldContent " .
|
||||
".InputfieldRepeaterItem[data-typeName=$itemTypeName] > .InputfieldHeader " .
|
||||
"{ background-color: #$matches[1] }";
|
||||
}
|
||||
}
|
||||
|
||||
$wrap->label = $wrapLabel;
|
||||
} else {
|
||||
$wrap->label = "$label " . (++$cnt);
|
||||
}
|
||||
$itemType = $this->getRepeaterItemType($page);
|
||||
$itemTypeName = $this->getRepeaterItemTypeName($itemType);
|
||||
$wrap->name = "repeater_item_{$page->id}";
|
||||
$wrap->wrapAttr('data-page', $page->id);
|
||||
$wrap->wrapAttr('data-type', $itemType);
|
||||
@@ -596,6 +610,11 @@ class InputfieldRepeater extends Inputfield implements InputfieldItemList {
|
||||
|
||||
// cache
|
||||
$this->form = $form;
|
||||
|
||||
if(!$isPost && count($typeStyles)) {
|
||||
$styles = "<style type='text/css'>" . implode("\n", $typeStyles) . "</style>";
|
||||
$this->wire()->adminTheme->addExtraMarkup('head', $styles);
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
Reference in New Issue
Block a user