1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-25 23:56:41 +02:00

Update InputfieldRepeater so that it also supports custom repeater item colors in Konkat default theme, plus some other adjustments

This commit is contained in:
Ryan Cramer
2025-08-22 15:14:49 -04:00
parent 0b4262b57b
commit 8ee607f06f
2 changed files with 49 additions and 26 deletions

View File

@@ -565,11 +565,13 @@ class AdminThemeUikit extends AdminThemeFramework implements Module, Configurabl
case 'none': break; case 'none': break;
} }
if(strpos($inputfield->attr('name'), '_repeater') === false || $themeBorder === 'card') {
switch($themeBorder) { switch($themeBorder) {
case 'none': $wrapClasses[] = 'InputfieldNoBorder'; break; case 'none': $wrapClasses[] = 'InputfieldNoBorder'; break;
case 'hide': $wrapClasses[] = 'InputfieldHideBorder'; break; case 'hide': $wrapClasses[] = 'InputfieldHideBorder'; break;
case 'card': $wrapClasses[] = 'uk-card uk-card-default'; break; case 'card': $wrapClasses[] = 'uk-card uk-card-default'; break;
} }
}
if($themeOffset && $themeOffset !== 'none') { if($themeOffset && $themeOffset !== 'none') {
$wrapClasses[] = 'InputfieldIsOffset'; $wrapClasses[] = 'InputfieldIsOffset';

View File

@@ -5,18 +5,18 @@
* *
* Maintains a collection of fields that are repeated for any number of times. * Maintains a collection of fields that are repeated for any number of times.
* *
* ProcessWire 3.x, Copyright 2024 by Ryan Cramer * ProcessWire 3.x, Copyright 2025 by Ryan Cramer
* https://processwire.com * https://processwire.com
* *
* @property int $repeaterMaxItems * @property int $repeaterMaxItems Maximum repeater items or 0 for no max (default=0)
* @property int $repeaterMinItems * @property int $repeaterMinItems Minimum repeater items or 0 for no min (default=0)
* @property int $repeaterDepth * @property int $repeaterDepth Maximum allowed depth for repeater items or 0 to disable (default=0)
* @property bool|int $familyFriendly * @property bool|int $familyFriendly This setting makes the admin page editor treat item depth as a parent/child relationship when it comes to sorting/moving items. (default=false)
* @property bool|int $familyToggle * @property bool|int $familyToggle When enabled, opening (or closing) a repeater item also opens (or closes) the next items that are visually children of it, when combined with familyFriendly mode. (default=false)
* @property bool|int $accordionMode * @property bool|int $accordionMode When enabled, only one repeater item will be open at a time. (default=false)
* @property bool|int $singleMode * @property bool|int $singleMode Limit repeater to a single item, primarily for the extending FieldsetPage module. (default=false)
* @property bool|int $loudControls Always show controls regardless of hover? * @property bool|int $loudControls Always show controls regardless of hover? (default=false)
* @property bool|int $noScroll Do not scroll to newly added items? * @property bool|int $noScroll Do not scroll to newly added items? (default=false)
* *
* @method string renderRepeaterLabel($label, $cnt, Page $page) * @method string renderRepeaterLabel($label, $cnt, Page $page)
* *
@@ -27,8 +27,8 @@ class InputfieldRepeater extends Inputfield implements InputfieldItemList {
public static function getModuleInfo() { public static function getModuleInfo() {
return array( return array(
'title' => __('Repeater', __FILE__), // Module Title 'title' => 'Repeater',
'summary' => __('Repeats fields from another template. Provides the input for FieldtypeRepeater.', __FILE__), // Module Summary 'summary' => 'Repeats fields from another template. Provides the input for FieldtypeRepeater.',
'version' => 111, 'version' => 111,
'requires' => 'FieldtypeRepeater', 'requires' => 'FieldtypeRepeater',
); );
@@ -393,7 +393,11 @@ class InputfieldRepeater extends Inputfield implements InputfieldItemList {
$minItems = $this->repeaterMinItems; $minItems = $this->repeaterMinItems;
// if there are a minimum required number of items, set them up now // if there are a minimum required number of items, set them up now
if(!$itemID && $minItems > 0) { if(!$itemID && $minItems > 0 && $value instanceof PageArray) {
$process = $this->wire()->process;
if($process instanceof WirePageEditor && $process->getPage()->id === $this->page->id) {
// do not enforce minItems when repeater page being edited directly
} else {
$notIDs = $value->explode('id'); $notIDs = $value->explode('id');
while($value->count() < $minItems) { while($value->count() < $minItems) {
$item = $this->getNextReadyPage($notIDs); $item = $this->getNextReadyPage($notIDs);
@@ -401,6 +405,7 @@ class InputfieldRepeater extends Inputfield implements InputfieldItemList {
$notIDs[] = $item->id; $notIDs[] = $item->id;
} }
} }
}
$repeaterCollapse = (int) $this->field->get('repeaterCollapse'); $repeaterCollapse = (int) $this->field->get('repeaterCollapse');
$cnt = 0; $cnt = 0;
@@ -485,6 +490,7 @@ class InputfieldRepeater extends Inputfield implements InputfieldItemList {
$itemType = $this->getRepeaterItemType($page); $itemType = $this->getRepeaterItemType($page);
$itemTypeName = $this->getRepeaterItemTypeName($itemType); $itemTypeName = $this->getRepeaterItemTypeName($itemType);
$hasCustomColor = false;
if(!$isPost) { if(!$isPost) {
$wrap->entityEncodeLabel = false; $wrap->entityEncodeLabel = false;
@@ -500,10 +506,24 @@ class InputfieldRepeater extends Inputfield implements InputfieldItemList {
// background-color definition // background-color definition
if(strlen($matches[1]) === 3 || strlen($matches[1]) === 6) { if(strlen($matches[1]) === 3 || strlen($matches[1]) === 6) {
$wrapLabel = str_replace($matches[0], '', $wrapLabel); $wrapLabel = str_replace($matches[0], '', $wrapLabel);
$hasCustomColor = true;
$typeStyles[$itemTypeName] = $typeStyles[$itemTypeName] =
".Inputfield_$this->name .InputfieldContent " . ".Inputfield_$this->name .InputfieldContent " .
".InputfieldRepeaterItem[data-typeName=\"$itemTypeName\"] > .InputfieldHeader " . ".InputfieldRepeaterItem[data-typeName=\"$itemTypeName\"]:not(.InputfieldRepeaterDeletePending) > " .
"{ background-color: #$matches[1]; outline-color: #$matches[1] }"; ".InputfieldHeader {" .
"background-color: #$matches[1]; " .
"outline-color: #$matches[1]; " .
"color: #fff; " .
"--pw-inputs-background: #$matches[1]; " .
"--pw-text-color: #fff; " .
"} " .
".Inputfield_$this->name .InputfieldContent " .
".InputfieldRepeaterItem[data-typeName=\"$itemTypeName\"]:not(.InputfieldRepeaterDeletePending) > " .
".InputfieldHeader .ui-priority-secondary {" .
"color: #fff; " .
"--pw-text-color: #fff; " .
"opacity: 0.8" .
"}";
} }
} }
@@ -517,6 +537,7 @@ class InputfieldRepeater extends Inputfield implements InputfieldItemList {
$wrap->wrapAttr('data-typeName', $itemTypeName); $wrap->wrapAttr('data-typeName', $itemTypeName);
$wrap->wrapAttr('data-fnsx', "_repeater$page->id"); // fnsx=field name suffix $wrap->wrapAttr('data-fnsx', "_repeater$page->id"); // fnsx=field name suffix
$wrap->wrapAttr('data-depth', $depth ? $depth->val() : '0'); $wrap->wrapAttr('data-depth', $depth ? $depth->val() : '0');
if($hasCustomColor) $wrap->addClass('InputfieldRepeaterColor');
if($wrapIcon) $wrap->wrapAttr('data-icon', $wrapIcon); if($wrapIcon) $wrap->wrapAttr('data-icon', $wrapIcon);
//$wrap->wrapAttr('data-editorPage', $this->page->id); //$wrap->wrapAttr('data-editorPage', $this->page->id);
//$wrap->wrapAttr('data-parentPage', $page->parent->id); //$wrap->wrapAttr('data-parentPage', $page->parent->id);
@@ -634,7 +655,7 @@ class InputfieldRepeater extends Inputfield implements InputfieldItemList {
$this->form = $form; $this->form = $form;
if(!$isPost && count($typeStyles)) { if(!$isPost && count($typeStyles)) {
$styles = "<style type='text/css'>" . implode("\n", $typeStyles) . "</style>"; $styles = "<style>" . implode("\n", $typeStyles) . "</style>";
if($this->wire()->config->ajax && ($this->page instanceof RepeaterPage || $this->hasPage instanceof RepeaterPage)) { if($this->wire()->config->ajax && ($this->page instanceof RepeaterPage || $this->hasPage instanceof RepeaterPage)) {
// ajax-rendered nested repeater page // ajax-rendered nested repeater page
$this->prependMarkup .= $styles; $this->prependMarkup .= $styles;