Studio Lambelet Posted June 18, 2022 Posted June 18, 2022 I'm working on a page builder module that extends FieldtypeMulti, with the same way of storing data as FieldtypePagetable (field value is a WireArray). I'm using ProcessWire 3.0.200 / PHP 8.1.6. Everything is working fine on all the pages I use this module except on the homepage (id = 1). If I try to save a new value on the homepage, the system throws the following error: Quote Failed to ready module: FieldtypePageBuilder - Can't save field from page 1: /: Call $page->of(false); before getting/setting values that will be modified and saved. [pageBuild1] Here is the code used for saving the field value: /** * Add a page to a PageBuilder * * @param int $parentForBuilder id of page that contains the builder * @param string $builderName the name of the PageBuilder field * @param int $newPageId the newly created page id * @param string $position position to add new bloc, can be: first, before, after, last * @param int $prevPageId either 0 or ID of page the new bloc should be before/after * * @return void * */ protected function addBlocToBuilder(int $parentForBuilder, string $builderName, int $newPageId, string $position, int $prevPageId) { $parentPage = $this->wire('pages')->get($parentForBuilder); if (!$parentPage->get($builderName)) { $this->exitError(400, __('Could not get builder.')); } // FYI, $builder is a WireArray $builder = $parentPage->get($builderName); if (!$builder) { $this->exitError(400, __('Could not update WireArray.')); } if ($position === 'first') { $builder->prepend($newPageId); } else if ($position === 'before') { $builder->insertBefore($newPageId, $prevPageId); } else if ($position === 'after') { $builder->insertAfter($newPageId, $prevPageId); } else { $builder->add($newPageId); } $saveState = $parentPage->setAndSave($builderName, $builder); return $saveState; } According to the documentation setAndSave "does not need output formatting to be turned off first". So I would not except this error. I also tried saving with the following code instead of setAndSave(), without success: $of = $parentPage->of(); $parentPage->of(false); $parentPage->set($builderName, $builder); $parentPage->save($builderName); $parentPage->of($of); I find it particularly weird that this bug only occurs on the homepage. One more thing that doesn't make sense to me: if I call a bar dump from Tracy Debugger before saving - e.g. bd(wire('user'); saving will success... I would be really happy if someone could give me some advice, I spent really too much time on this bug. Thanks in advance!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now