Skip to content

Commit

Permalink
Fix issue processwire/processwire-issues#719 where 'parent' property …
Browse files Browse the repository at this point in the history
…didn't work for $page->setAndSave()
  • Loading branch information
ryancramerdesign committed Nov 29, 2018
1 parent fcc353b commit 0cb693c
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions wire/core/Page.php
Expand Up @@ -1177,7 +1177,6 @@ public function get($key) {
*
* @param string|int|Field $field
* @return Field|null
* @throws WireException if given invalid argument
* @todo determine if we can always retrieve in context regardless of output formatting.
*
*/
Expand Down Expand Up @@ -2575,27 +2574,30 @@ public function getLanguages() {
*
*/
public function save($field = null, array $options = array()) {

if(is_array($field) && empty($options)) {
$options = $field;
$field = null;
}
if(!is_null($field)) {
if($this->hasField($field)) {
return $this->wire('pages')->saveField($this, $field, $options);
} else if(is_string($field) && (isset($this->settings[$field]) || parent::get($field) !== null)) {
$options['noFields'] = true;
return $this->wire('pages')->save($this, $options);
} else {
return false;
}

if(empty($field)) {
return $this->wire('pages')->save($this, $options);
}

if($this->hasField($field)) {
// save field
return $this->wire('pages')->saveField($this, $field, $options);
}

// save only native properties
$options['noFields'] = true;
return $this->wire('pages')->save($this, $options);
}

/**
* Quickly set field value(s) and save to database
*
* You can specify a single vield and value, or an array of fields and values.
* You can specify a single field and value, or an array of fields and values.
*
* This method does not need output formatting to be turned off first, so make sure that whatever
* value(s) you set are not formatted values.
Expand Down Expand Up @@ -3935,7 +3937,7 @@ protected function isEqual($key, $value1, $value2) {
* Return a Page helper class instance that's common among all Page objects in this ProcessWire instance
*
* @param $className
* @return object
* @return object|PageComparison|PageAccess|PageTraversal
*
*/
protected function getHelperInstance($className) {
Expand Down Expand Up @@ -4019,7 +4021,6 @@ public function ___setEditor(WirePageEditor $editor) {
* #pw-internal
*
* @param PageArray|bool|null $items Traversal pages (PageArray), boolean false to unset, or omit to get.
* @throws WireException if given $siblings that do not include $this page.
* @return PageArray|null
* @since 3.0.116
*
Expand Down Expand Up @@ -4125,7 +4126,7 @@ public function _lazy($lazy = null) {
* @param string $method The $pages API method to call (get, find, findOne, or count)
* @param string|int $selector The selector argument of the $pages call
* @param array $options Any additional options (see Pages::find for options).
* @return Pages|Page|PageArray|NullPage
* @return Pages|Page|PageArray|NullPage|int
* @throws WireException
*
*/
Expand Down

0 comments on commit 0cb693c

Please sign in to comment.