1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-13 18:24:57 +02:00

Some minor repeater adjustments to support derived fieldtype in progress

This commit is contained in:
Ryan Cramer
2017-08-25 10:15:10 -04:00
parent c9fca29283
commit fc2b7944a2
4 changed files with 48 additions and 9 deletions

View File

@@ -355,13 +355,19 @@ class FieldtypeRepeater extends Fieldtype implements ConfigurableModule {
// check for nested repeater // check for nested repeater
foreach($repeaters as $name) { foreach($repeaters as $name) {
$repeaterItems = $ownerPage->get($name); $repeaterItems = $ownerPage->get($name);
if(!$repeaterItems || !$repeaterItems instanceof PageArray) continue; if(!$repeaterItems) continue;
foreach($repeaterItems as $nestedOwnerPage) { if($repeaterItems instanceof PageArray) {
// perform recursive check foreach($repeaterItems as $nestedOwnerPage) {
$hasField = $this->isRepeaterItemValidOnPage($repeaterItem, $nestedOwnerPage); // perform recursive check
if($hasField) break; $hasField = $this->isRepeaterItemValidOnPage($repeaterItem, $nestedOwnerPage);
if($hasField) break;
}
} else if($repeaterItems instanceof RepeaterPage) {
// for single item value (i.e. FieldtypeFieldsetPage)
$hasField = $this->isRepeaterItemValidOnPage($repeaterItem, $repeaterItems);
} else {
continue;
} }
if($hasField) break;
} }
return $hasField; return $hasField;
@@ -1322,6 +1328,14 @@ class FieldtypeRepeater extends Fieldtype implements ConfigurableModule {
if(!$page->id || !$field->id) return false; if(!$page->id || !$field->id) return false;
$value = $page->get($field->name); $value = $page->get($field->name);
if($value instanceof RepeaterPage) {
// for FieldsetPage compatibility
$pageArray = $this->getBlankValue($page, $field);
$pageArray->add($value);
$pageArray->resetTrackChanges();
$value = $pageArray;
}
// pages that will be saved // pages that will be saved
$savePages = array(); $savePages = array();

View File

@@ -61,6 +61,12 @@
display: none; } display: none; }
.Inputfields .InputfieldRepeater .InputfieldRepeaterDelete { .Inputfields .InputfieldRepeater .InputfieldRepeaterDelete {
display: none; } display: none; }
.Inputfields .InputfieldRepeater.InputfieldRepeaterSingle > .InputfieldContent > .Inputfields {
margin-bottom: 0; }
.Inputfields .InputfieldRepeater.InputfieldRepeaterSingle > .InputfieldContent > .Inputfields > .InputfieldRepeaterItem {
margin-bottom: 0; }
.Inputfields .InputfieldRepeater.InputfieldRepeaterSingle > .InputfieldContent > .Inputfields > .InputfieldRepeaterItem > .InputfieldHeader {
display: none; }
.InputfieldRepeater .InputfieldWrapper, .InputfieldRepeater .InputfieldWrapper,
.InputfieldRepeater .InputfieldWrapper > .Inputfields { .InputfieldRepeater .InputfieldWrapper > .Inputfields {

View File

@@ -579,16 +579,22 @@ class InputfieldRepeater extends Inputfield implements InputfieldItemList {
$this->wire('modules')->get('JqueryUI')->use('vex'); $this->wire('modules')->get('JqueryUI')->use('vex');
$this->preloadInputfieldAssets(); $this->preloadInputfieldAssets();
$min = (int) $this->repeaterMinItems;
$max = (int) $this->repeaterMaxItems;
if($this->field->get('repeaterLoading') == FieldtypeRepeater::loadingOff) { if($this->field->get('repeaterLoading') == FieldtypeRepeater::loadingOff) {
$this->addClass('InputfieldRepeaterNoAjaxAdd', 'wrapClass'); $this->addClass('InputfieldRepeaterNoAjaxAdd', 'wrapClass');
} }
if($this->repeaterMaxItems > 0) { if($max > 0) {
$this->addClass('InputfieldRepeaterMax', 'wrapClass'); $this->addClass('InputfieldRepeaterMax', 'wrapClass');
} }
if($this->repeaterMinItems > 0) { if($min > 0) {
$this->addClass('InputfieldRepeaterMin', 'wrapClass'); $this->addClass('InputfieldRepeaterMin', 'wrapClass');
} }
if($this->repeaterDepth > 0) { if($min === 1 && $max === 1) {
$this->addClass('InputfieldRepeaterSingle', 'wrapClass');
} else if($this->repeaterDepth > 0) {
$this->addClass('InputfieldRepeaterDepth', 'wrapClass'); $this->addClass('InputfieldRepeaterDepth', 'wrapClass');
} }
if($this->accordionMode) { if($this->accordionMode) {

View File

@@ -111,6 +111,19 @@
display: none; display: none;
} }
&.InputfieldRepeaterSingle {
// repeater in single-item mode
> .InputfieldContent > .Inputfields {
margin-bottom: 0;
> .InputfieldRepeaterItem {
margin-bottom: 0;
> .InputfieldHeader {
display: none;
}
}
}
}
} }
.InputfieldRepeater { .InputfieldRepeater {