mirror of
https://github.com/processwire/processwire.git
synced 2025-08-24 23:31:01 +02:00
Update FieldtypePage to implement the Fieldtype::__importValue() method for page import support
This commit is contained in:
@@ -314,6 +314,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.
|
||||
*
|
||||
|
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user