diff --git a/wire/modules/Fieldtype/FieldtypePage.module b/wire/modules/Fieldtype/FieldtypePage.module index 026c3cc9..67829960 100644 --- a/wire/modules/Fieldtype/FieldtypePage.module +++ b/wire/modules/Fieldtype/FieldtypePage.module @@ -288,7 +288,7 @@ class FieldtypePage extends FieldtypeMulti implements Module, ConfigurableModule if(!empty($options['human'])) return implode("\n", $a); return $a; } - + protected function exportValuePage(Page $page, Field $field, Page $value, array $options = array()) { if($page) {} if($field) {} @@ -313,6 +313,42 @@ class FieldtypePage extends FieldtypeMulti implements Module, ConfigurableModule } return $a; } + + /** + * Import value + * + * @param Page $page + * @param Field $field + * @param array|string $value + * @param array $options + * @return PageArray + * + */ + public function ___importValue(Page $page, Field $field, $value, array $options = array()) { + $pageArray = $this->wire('pages')->newPageArray(); + if(empty($value)) return $pageArray; + if(is_string($value)) $value = array($value); + foreach($value as $item) { + if(is_array($item)) { + $path = $item['path']; + } else if(is_string($item)) { + // system option + $path = $item; + } + $p = $this->wire('pages')->get($path); + if(!$p->id) { + $pageArray->error("Unable to find page '$path' to add to field '$field->name'"); + } else if(!$this->isValidPage($p, $field, $page)) { + $reason = $page->get('_isValidPage'); + $warning = "Page '$p->path' is not allowed by field '$field->name' " . ($reason ? "($reason)" : ""); + $pageArray->error($warning); + } else { + $pageArray->add($p); + } + } + return $pageArray; + } + /** * Format the given value for output. diff --git a/wire/modules/Inputfield/InputfieldPage/InputfieldPage.module b/wire/modules/Inputfield/InputfieldPage/InputfieldPage.module index 32e46307..a69f24eb 100644 --- a/wire/modules/Inputfield/InputfieldPage/InputfieldPage.module +++ b/wire/modules/Inputfield/InputfieldPage/InputfieldPage.module @@ -220,7 +220,7 @@ class InputfieldPage extends Inputfield implements ConfigurableModule { if(!$field instanceof Field) throw new WireException('isValidPage requires a valid Field or field name'); if($editPage && $page->id == $editPage->id) { - $editPage->set('_isValidPage', "Page is referencing itself and circular page reference not allowed"); + $editPage->setQuietly('_isValidPage', "Page is referencing itself and circular page reference not allowed"); return false; // prevent circular reference } @@ -242,7 +242,7 @@ class InputfieldPage extends Inputfield implements ConfigurableModule { // looks like its okay } else { // also fails $pages->cont() check, so definitely not valid - if($editPage) $editPage->set('_isValidPage', "Page $page does not match findPagesSelector: $selector"); + if($editPage) $editPage->setQuietly('_isValidPage', "Page $page does not match findPagesSelector: $selector"); $valid = false; } } @@ -265,7 +265,7 @@ class InputfieldPage extends Inputfield implements ConfigurableModule { $valid = false; } if(!$valid && $editPage) { - $editPage->set('_isValidPage', "Page $page does not have required parent $parent_id"); + $editPage->setQuietly('_isValidPage', "Page $page does not have required parent $parent_id"); } } else { // PHP version prior to 5.3.8 @@ -283,7 +283,7 @@ class InputfieldPage extends Inputfield implements ConfigurableModule { if(!$hasRequiredTemplate) { $valid = false; if($editPage) { - $editPage->set('_isValidPage', "Page $page does not have required template(s): " . implode(',', $template_ids)); + $editPage->setQuietly('_isValidPage', "Page $page does not have required template(s): " . implode(',', $template_ids)); } }