diff --git a/wire/core/PagesEditor.php b/wire/core/PagesEditor.php index ee742e88..1f301cf0 100644 --- a/wire/core/PagesEditor.php +++ b/wire/core/PagesEditor.php @@ -363,7 +363,7 @@ class PagesEditor extends Wire { // assign sort order if($page->sort < 0) { - $page->sort = $page->parent->numChildren(); + $page->sort = ($parent->id ? $parent->numChildren() : 0); } // assign any default values for fields diff --git a/wire/core/WireMailTools.php b/wire/core/WireMailTools.php index 8ee8f354..c813b150 100644 --- a/wire/core/WireMailTools.php +++ b/wire/core/WireMailTools.php @@ -3,7 +3,7 @@ /** * ProcessWire Mail Tools ($mail API variable) * - * ProcessWire 3.x, Copyright 2019 by Ryan Cramer + * ProcessWire 3.x, Copyright 2023 by Ryan Cramer * https://processwire.com * * #pw-summary Provides an API interface to email and WireMail. @@ -66,11 +66,10 @@ class WireMailTools extends Wire { /** @var WireMail|null $mail */ $mail = null; - /** @var Modules $modules */ - $modules = $this->wire('modules'); + $modules = $this->wire()->modules; // merge config settings with requested options - $settings = $this->wire('config')->wireMail; + $settings = $this->wire()->config->wireMail; if(!is_array($settings)) $settings = array(); if(count($options)) $settings = array_merge($settings, $options); @@ -179,7 +178,7 @@ class WireMailTools extends Wire { $options = array_merge($defaults, $options); if(!empty($options['replyTo'])) { - $replyTo = $this->wire('sanitizer')->email($options['replyTo']); + $replyTo = $this->wire()->sanitizer->email($options['replyTo']); if($replyTo) $options['headers']['Reply-to'] = $replyTo; unset($options['replyTo']); } @@ -190,7 +189,9 @@ class WireMailTools extends Wire { if(strlen($from)) $mail->from($from); if(strlen($options['bodyHTML'])) $mail->bodyHTML($options['bodyHTML']); if(strlen($options['body'])) $mail->body($options['body']); - if(count($options['headers'])) foreach($options['headers'] as $k => $v) $mail->header($k, $v); + if(count($options['headers'])) { + foreach($options['headers'] as $k => $v) $mail->header($k, $v); + } // send along any options we don't recognize foreach($options as $key => $value) { if(!array_key_exists($key, $defaults)) $mail->$key = $value; @@ -198,7 +199,7 @@ class WireMailTools extends Wire { $numSent = $mail->send(); } catch(\Exception $e) { - if($this->wire('config')->debug) $mail->error($e->getMessage()); + if($this->wire()->config->debug) $mail->error($e->getMessage()); $mail->trackException($e, false); $numSent = 0; } @@ -439,12 +440,12 @@ class WireMailTools extends Wire { $options = count($options) ? array_merge($defaults, $options) : $defaults; $blacklist = $options['blacklist']; - if(empty($blacklist)) $blacklist = $this->wire('config')->wireMail('blacklist'); + if(empty($blacklist)) $blacklist = $this->wire()->config->wireMail('blacklist'); if(empty($blacklist)) return false; if(!is_array($blacklist)) throw new WireException("Email blacklist must be array"); $inBlacklist = false; - $tt = $this->wire('sanitizer')->getTextTools(); + $tt = $this->wire()->sanitizer->getTextTools(); $email = trim($tt->strtolower($email)); if(strpos($email, '@') === false) { @@ -494,4 +495,4 @@ class WireMailTools extends Wire { } -} \ No newline at end of file +} diff --git a/wire/modules/Fieldtype/FieldtypeRepeater/FieldtypeFieldsetPage.module b/wire/modules/Fieldtype/FieldtypeRepeater/FieldtypeFieldsetPage.module index 46bdc4b8..b44595f9 100644 --- a/wire/modules/Fieldtype/FieldtypeRepeater/FieldtypeFieldsetPage.module +++ b/wire/modules/Fieldtype/FieldtypeRepeater/FieldtypeFieldsetPage.module @@ -7,7 +7,7 @@ require_once(dirname(__FILE__) . '/FieldtypeRepeater.module'); * * Maintains a collection of fields as a fieldset via an independent Page. * - * ProcessWire 3.x, Copyright 2021 by Ryan Cramer + * ProcessWire 3.x, Copyright 2023 by Ryan Cramer * https://processwire.com * * @property int $repeatersRootPageID @@ -95,9 +95,9 @@ class FieldtypeFieldsetPage extends FieldtypeRepeater implements ConfigurableMod * */ public function getRepeaterPageArray(Page $page, Field $field, $value = null) { - if($value && $value instanceof PageArray) return $value; + if($value instanceof PageArray) return $value; $pageArray = parent::getBlankValue($page, $field); - if($value && $value instanceof Page) $pageArray->add($value); + if($value instanceof Page) $pageArray->add($value); $pageArray->resetTrackChanges(); return $pageArray; } @@ -117,7 +117,7 @@ class FieldtypeFieldsetPage extends FieldtypeRepeater implements ConfigurableMod * * @param Page $page * @param Field $field - * @return FieldsetPage|PageArray + * @return FieldsetPage * */ public function getBlankValue(Page $page, Field $field) { @@ -198,7 +198,7 @@ class FieldtypeFieldsetPage extends FieldtypeRepeater implements ConfigurableMod * * @param Page $page * @param Field $field - * @param array $value + * @param array|Page $value * @return FieldsetPage|Page $value * */ @@ -394,7 +394,7 @@ class FieldtypeFieldsetPage extends FieldtypeRepeater implements ConfigurableMod * * @param Page $page Page object to save. * @param Field $field Field to retrieve from the page. - * @return mixed|null + * @return FieldsetPage * */ public function ___loadPageField(Page $page, Field $field) { @@ -411,13 +411,15 @@ class FieldtypeFieldsetPage extends FieldtypeRepeater implements ConfigurableMod */ public function ___savePageField(Page $page, Field $field) { + $pages = $this->wire()->pages; + if(!$page->id || !$field->id) return false; if($page->get('_cloning') instanceof Page) { // $page is being cloned, so lets also clone the FieldsetPage $source = $page->get('_cloning')->get($field->name); if(!$source->id) return false; - $target = $this->wire('pages')->clone($source, null, false, array( + $target = $pages->clone($source, null, false, array( 'uncacheAll' => false, 'set' => array('name' => self::repeaterPageNamePrefix . $page->id) )); @@ -441,7 +443,7 @@ class FieldtypeFieldsetPage extends FieldtypeRepeater implements ConfigurableMod if($value->isHidden()) $value->removeStatus(Page::statusHidden); } - $this->wire()->pages->save($value, array('uncacheAll' => false)); + $pages->save($value, array('uncacheAll' => false)); $database = $this->wire()->database; $table = $database->escapeTable($field->table);