mirror of
https://github.com/processwire/processwire.git
synced 2025-08-11 01:04:16 +02:00
Update RepeaterPage class with methods to identify root forField and forPage in nested repeaters
This commit is contained in:
@@ -115,6 +115,52 @@ class RepeaterPage extends Page {
|
||||
return $this->forField;
|
||||
}
|
||||
|
||||
/**
|
||||
* For nested repeaters, returns the root level forPage and forField in an array
|
||||
*
|
||||
* @param string $get Specify 'page' or 'field' or omit for array of both
|
||||
* @return array|Page|Field
|
||||
* @since 3.0.132
|
||||
*
|
||||
*/
|
||||
protected function getForRoot($get = '') {
|
||||
$forPage = $this->getForPage();
|
||||
$forField = $this->getForField();
|
||||
$n = 0;
|
||||
while($forPage instanceof RepeaterPage && ++$n < 20) {
|
||||
$forField = $forPage->getForField();
|
||||
$forPage = $forPage->getForPage();
|
||||
}
|
||||
if($forPage instanceof RepeaterPage) {
|
||||
$forPage = new NullPage();
|
||||
}
|
||||
if($get === 'page') return $forPage;
|
||||
if($get === 'field') return $forField;
|
||||
return array('page' => $forPage, 'field' => $forField);
|
||||
}
|
||||
|
||||
/**
|
||||
* For nested repeaters, return the root-level field that this repeater item belongs to
|
||||
*
|
||||
* @return Field
|
||||
* @since 3.0.132
|
||||
*
|
||||
*/
|
||||
public function getForFieldRoot() {
|
||||
return $this->getForRoot('field');
|
||||
}
|
||||
|
||||
/**
|
||||
* For nested repeaters, return the root-level non-repeater page that this repeater item belongs to
|
||||
*
|
||||
* @return Page
|
||||
* @since 3.0.132
|
||||
*
|
||||
*/
|
||||
public function getForPageRoot() {
|
||||
return $this->getForRoot('page');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get property
|
||||
*
|
||||
@@ -181,5 +227,28 @@ class RepeaterPage extends Page {
|
||||
public function isReady() {
|
||||
return $this->isUnpublished() && $this->isHidden();
|
||||
}
|
||||
|
||||
/**
|
||||
* Track a change to a property in this object
|
||||
*
|
||||
* The change will only be recorded if change tracking is enabled for this object instance.
|
||||
*
|
||||
* #pw-group-changes
|
||||
*
|
||||
* @param string $what Name of property that changed
|
||||
* @param mixed $old Previous value before change
|
||||
* @param mixed $new New value
|
||||
* @return $this
|
||||
*
|
||||
public function trackChange($what, $old = null, $new = null) {
|
||||
parent::trackChange($what, $old, $new);
|
||||
if($this->trackChanges()) {
|
||||
$forPage = $this->getForPage();
|
||||
$forField = $this->getForField();
|
||||
if($forPage->id && $forField) $forPage->trackChange($forField->name);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user