mirror of
https://github.com/processwire/processwire.git
synced 2025-08-15 19:24:28 +02:00
Update InputfieldPage to support dynamic page properties in selector when used without FieldtypePage
This commit is contained in:
@@ -957,6 +957,7 @@ class InputfieldPage extends Inputfield implements ConfigurableModule {
|
|||||||
*/
|
*/
|
||||||
public function ___processInput(WireInputData $input) {
|
public function ___processInput(WireInputData $input) {
|
||||||
|
|
||||||
|
$process = $this->wire()->process;
|
||||||
$pages = $this->wire()->pages;
|
$pages = $this->wire()->pages;
|
||||||
$user = $this->wire()->user;
|
$user = $this->wire()->user;
|
||||||
|
|
||||||
@@ -969,6 +970,15 @@ class InputfieldPage extends Inputfield implements ConfigurableModule {
|
|||||||
$existingValueStr = $value ? "$value" : '';
|
$existingValueStr = $value ? "$value" : '';
|
||||||
$newValue = null;
|
$newValue = null;
|
||||||
|
|
||||||
|
// the $editPage is used when InputfieldPage used without FieldtypePage
|
||||||
|
if($process instanceof WirePageEditor) {
|
||||||
|
$editPage = $process->getPage();
|
||||||
|
} else if($this->hasPage) {
|
||||||
|
$editPage = $this->hasPage;
|
||||||
|
} else {
|
||||||
|
$editPage = new Page();
|
||||||
|
}
|
||||||
|
|
||||||
if($inputfield instanceof InputfieldSupportsArrayValue) {
|
if($inputfield instanceof InputfieldSupportsArrayValue) {
|
||||||
$value = $inputfield->getArrayValue();
|
$value = $inputfield->getArrayValue();
|
||||||
} else {
|
} else {
|
||||||
@@ -977,7 +987,6 @@ class InputfieldPage extends Inputfield implements ConfigurableModule {
|
|||||||
|
|
||||||
if(is_array($value)) {
|
if(is_array($value)) {
|
||||||
$newValue = $pages->newPageArray();
|
$newValue = $pages->newPageArray();
|
||||||
$mockPage = new Page();
|
|
||||||
foreach($value as $v) {
|
foreach($value as $v) {
|
||||||
$id = (int) $v;
|
$id = (int) $v;
|
||||||
if(!$id) continue;
|
if(!$id) continue;
|
||||||
@@ -985,9 +994,9 @@ class InputfieldPage extends Inputfield implements ConfigurableModule {
|
|||||||
// existing page
|
// existing page
|
||||||
$page = $pages->get($id);
|
$page = $pages->get($id);
|
||||||
|
|
||||||
if(!$this->hasFieldtype && !self::isValidPage($page, $this, $mockPage)) {
|
if(!$this->hasFieldtype && !self::isValidPage($page, $this, $editPage)) {
|
||||||
// extra validation for usage without FieldtypePage
|
// extra validation for usage without FieldtypePage
|
||||||
$error = $mockPage->get('_isValidPage');
|
$error = $editPage->get('_isValidPage');
|
||||||
if($error) $this->error($error);
|
if($error) $this->error($error);
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -1012,9 +1021,8 @@ class InputfieldPage extends Inputfield implements ConfigurableModule {
|
|||||||
if($newValue->hasStatus(Page::statusUnpublished) && !$this->getSetting('allowUnpub')) {
|
if($newValue->hasStatus(Page::statusUnpublished) && !$this->getSetting('allowUnpub')) {
|
||||||
$newValue = null; // disallow unpublished
|
$newValue = null; // disallow unpublished
|
||||||
} else if($newValue && $newValue->id && !$this->hasFieldtype) {
|
} else if($newValue && $newValue->id && !$this->hasFieldtype) {
|
||||||
$mockPage = new Page();
|
if(!self::isValidPage($newValue, $this, $editPage)) {
|
||||||
if(!self::isValidPage($newValue, $this, $mockPage)) {
|
$error = $editPage->get('_isValidPage');
|
||||||
$error = $mockPage->get('_isValidPage');
|
|
||||||
if($error) $this->error($error);
|
if($error) $this->error($error);
|
||||||
$newValue = null;
|
$newValue = null;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user