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:
@@ -565,10 +565,12 @@ class AdminThemeUikit extends AdminThemeFramework implements Module, Configurabl
|
||||
case 'none': break;
|
||||
}
|
||||
|
||||
switch($themeBorder) {
|
||||
case 'none': $wrapClasses[] = 'InputfieldNoBorder'; break;
|
||||
case 'hide': $wrapClasses[] = 'InputfieldHideBorder'; break;
|
||||
case 'card': $wrapClasses[] = 'uk-card uk-card-default'; break;
|
||||
if(strpos($inputfield->attr('name'), '_repeater') === false || $themeBorder === 'card') {
|
||||
switch($themeBorder) {
|
||||
case 'none': $wrapClasses[] = 'InputfieldNoBorder'; break;
|
||||
case 'hide': $wrapClasses[] = 'InputfieldHideBorder'; break;
|
||||
case 'card': $wrapClasses[] = 'uk-card uk-card-default'; break;
|
||||
}
|
||||
}
|
||||
|
||||
if($themeOffset && $themeOffset !== 'none') {
|
||||
|
@@ -5,18 +5,18 @@
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* @property int $repeaterMaxItems
|
||||
* @property int $repeaterMinItems
|
||||
* @property int $repeaterDepth
|
||||
* @property bool|int $familyFriendly
|
||||
* @property bool|int $familyToggle
|
||||
* @property bool|int $accordionMode
|
||||
* @property bool|int $singleMode
|
||||
* @property bool|int $loudControls Always show controls regardless of hover?
|
||||
* @property bool|int $noScroll Do not scroll to newly added items?
|
||||
* @property int $repeaterMaxItems Maximum repeater items or 0 for no max (default=0)
|
||||
* @property int $repeaterMinItems Minimum repeater items or 0 for no min (default=0)
|
||||
* @property int $repeaterDepth Maximum allowed depth for repeater items or 0 to disable (default=0)
|
||||
* @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 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 When enabled, only one repeater item will be open at a time. (default=false)
|
||||
* @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? (default=false)
|
||||
* @property bool|int $noScroll Do not scroll to newly added items? (default=false)
|
||||
*
|
||||
* @method string renderRepeaterLabel($label, $cnt, Page $page)
|
||||
*
|
||||
@@ -27,8 +27,8 @@ class InputfieldRepeater extends Inputfield implements InputfieldItemList {
|
||||
|
||||
public static function getModuleInfo() {
|
||||
return array(
|
||||
'title' => __('Repeater', __FILE__), // Module Title
|
||||
'summary' => __('Repeats fields from another template. Provides the input for FieldtypeRepeater.', __FILE__), // Module Summary
|
||||
'title' => 'Repeater',
|
||||
'summary' => 'Repeats fields from another template. Provides the input for FieldtypeRepeater.',
|
||||
'version' => 111,
|
||||
'requires' => 'FieldtypeRepeater',
|
||||
);
|
||||
@@ -393,12 +393,17 @@ class InputfieldRepeater extends Inputfield implements InputfieldItemList {
|
||||
$minItems = $this->repeaterMinItems;
|
||||
|
||||
// if there are a minimum required number of items, set them up now
|
||||
if(!$itemID && $minItems > 0) {
|
||||
$notIDs = $value->explode('id');
|
||||
while($value->count() < $minItems) {
|
||||
$item = $this->getNextReadyPage($notIDs);
|
||||
$value->add($item);
|
||||
$notIDs[] = $item->id;
|
||||
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');
|
||||
while($value->count() < $minItems) {
|
||||
$item = $this->getNextReadyPage($notIDs);
|
||||
$value->add($item);
|
||||
$notIDs[] = $item->id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -485,6 +490,7 @@ class InputfieldRepeater extends Inputfield implements InputfieldItemList {
|
||||
|
||||
$itemType = $this->getRepeaterItemType($page);
|
||||
$itemTypeName = $this->getRepeaterItemTypeName($itemType);
|
||||
$hasCustomColor = false;
|
||||
|
||||
if(!$isPost) {
|
||||
$wrap->entityEncodeLabel = false;
|
||||
@@ -500,10 +506,24 @@ class InputfieldRepeater extends Inputfield implements InputfieldItemList {
|
||||
// background-color definition
|
||||
if(strlen($matches[1]) === 3 || strlen($matches[1]) === 6) {
|
||||
$wrapLabel = str_replace($matches[0], '', $wrapLabel);
|
||||
$hasCustomColor = true;
|
||||
$typeStyles[$itemTypeName] =
|
||||
".Inputfield_$this->name .InputfieldContent " .
|
||||
".InputfieldRepeaterItem[data-typeName=\"$itemTypeName\"] > .InputfieldHeader " .
|
||||
"{ background-color: #$matches[1]; outline-color: #$matches[1] }";
|
||||
".InputfieldRepeaterItem[data-typeName=\"$itemTypeName\"]:not(.InputfieldRepeaterDeletePending) > " .
|
||||
".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-fnsx', "_repeater$page->id"); // fnsx=field name suffix
|
||||
$wrap->wrapAttr('data-depth', $depth ? $depth->val() : '0');
|
||||
if($hasCustomColor) $wrap->addClass('InputfieldRepeaterColor');
|
||||
if($wrapIcon) $wrap->wrapAttr('data-icon', $wrapIcon);
|
||||
//$wrap->wrapAttr('data-editorPage', $this->page->id);
|
||||
//$wrap->wrapAttr('data-parentPage', $page->parent->id);
|
||||
@@ -634,7 +655,7 @@ class InputfieldRepeater extends Inputfield implements InputfieldItemList {
|
||||
$this->form = $form;
|
||||
|
||||
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)) {
|
||||
// ajax-rendered nested repeater page
|
||||
$this->prependMarkup .= $styles;
|
||||
|
Reference in New Issue
Block a user