mirror of
https://github.com/processwire/processwire.git
synced 2025-08-24 15:23:11 +02:00
Update FieldtypePage to implement the Fieldtype::__importValue() method for page import support
This commit is contained in:
@@ -288,7 +288,7 @@ class FieldtypePage extends FieldtypeMulti implements Module, ConfigurableModule
|
|||||||
if(!empty($options['human'])) return implode("\n", $a);
|
if(!empty($options['human'])) return implode("\n", $a);
|
||||||
return $a;
|
return $a;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function exportValuePage(Page $page, Field $field, Page $value, array $options = array()) {
|
protected function exportValuePage(Page $page, Field $field, Page $value, array $options = array()) {
|
||||||
if($page) {}
|
if($page) {}
|
||||||
if($field) {}
|
if($field) {}
|
||||||
@@ -313,6 +313,42 @@ class FieldtypePage extends FieldtypeMulti implements Module, ConfigurableModule
|
|||||||
}
|
}
|
||||||
return $a;
|
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.
|
* 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(!$field instanceof Field) throw new WireException('isValidPage requires a valid Field or field name');
|
||||||
|
|
||||||
if($editPage && $page->id == $editPage->id) {
|
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
|
return false; // prevent circular reference
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -242,7 +242,7 @@ class InputfieldPage extends Inputfield implements ConfigurableModule {
|
|||||||
// looks like its okay
|
// looks like its okay
|
||||||
} else {
|
} else {
|
||||||
// also fails $pages->cont() check, so definitely not valid
|
// 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;
|
$valid = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -265,7 +265,7 @@ class InputfieldPage extends Inputfield implements ConfigurableModule {
|
|||||||
$valid = false;
|
$valid = false;
|
||||||
}
|
}
|
||||||
if(!$valid && $editPage) {
|
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 {
|
} else {
|
||||||
// PHP version prior to 5.3.8
|
// PHP version prior to 5.3.8
|
||||||
@@ -283,7 +283,7 @@ class InputfieldPage extends Inputfield implements ConfigurableModule {
|
|||||||
if(!$hasRequiredTemplate) {
|
if(!$hasRequiredTemplate) {
|
||||||
$valid = false;
|
$valid = false;
|
||||||
if($editPage) {
|
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