Jump to content

Recommended Posts

Posted

Today I used this:

$clone = wire()->pages->clone($p, recursive: false);

And I wondered why it was still cloning my page "$p" recursively with all its children...

Then I tried this:

$clone = wire()->pages->clone($p, null, false);

Which worked as expected. I looked into the code but was not able to find an explanation. AI was also not helpful in this case.

Any ideas?

Posted

I think $parent is the second parameter not the recursive flag (which is true by default)? 🤔

Posted

Hey @elabx thx for joining! Yes, but using named arguments it should not matter, so using "recursive: false" should set the "$recursive" parameter (which is the third) and the second should default to null either way. But something is not working as it should in my opinion, so something is wrong either in my head or in the core ^^

PS: Here are the links to the methods in the core:

Pages::___clone = https://github.com/processwire/processwire/blob/44fcf13ea2d7f14a04eed54c29afcc79eb46ec45/wire/core/Pages.php#L1047

PagesEditor::_clone = https://github.com/processwire/processwire/blob/44fcf13ea2d7f14a04eed54c29afcc79eb46ec45/wire/core/PagesEditor.php#L1324

Posted
31 minutes ago, bernhard said:

so using "recursive: false" should set the "$recursive" parameter (which is the third) and the second should default to null either way.

I completely missed this syntax! I am living in the PHP of the past 😭

  • Like 1

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...