Skip to content
This repository has been archived by the owner on Oct 6, 2022. It is now read-only.

$page->update not working with autoid #49

Open
philipmarnef opened this issue Jul 29, 2020 · 2 comments
Open

$page->update not working with autoid #49

philipmarnef opened this issue Jul 29, 2020 · 2 comments
Assignees
Labels
bug Something isn't working enhancement New feature or request

Comments

@philipmarnef
Copy link

I have blueprint with an autoid field. If I try this:

$page = Page::create($props);
$page->update($newprops);

The updated fields are in the $page object, but the .txt file is not updated.

Problem is gone when I remove the autoid field.

@philipmarnef
Copy link
Author

Following up: I didn't add

'autoid' => autoid()

to the $props array. When I do, it works.

I'm guessing the autoID is added in a hook which changes the page between create & update so $page->update() doesn't resolve?

@bnomei bnomei self-assigned this Aug 10, 2020
@bnomei bnomei added bug Something isn't working enhancement New feature or request labels Aug 10, 2020
@bnomei
Copy link
Owner

bnomei commented Aug 10, 2020

i never tried with Page::create but used $parent->createChild().

https://github.com/bnomei/kirby3-autoid/wiki/PHP:-autoid(),-Field-Method-fromAutoID()#create-a-pagefile-programmatically-and-retrieve-autoid

it would be a problem if the autoid registered hook at create changed the object and breaks expected behaviour. the only way around that is using a custom create method add add the autoid there
https://getkirby.com/kosmos/45#kirby-tip-of-the-month

i will think about adding a AutoidPage to inherit from that avoids this.

class AutoidPage extends Page
{

  public static function create(array $props): Page
  {
    $props['autoid') = autoid(); // generate new
    return parent::create($props);
  }
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants