Skip to content

"noHooks" option for Page::save() doesn't call Pages::save() and Pages::saveField() with underscores #1405

Open
@Toutouwai

Description

@Toutouwai

Short description of the issue

Related forum topic: https://processwire.com/talk/topic/25850-nohooks-option-in-page-save/

The documentation for the options argument of Page::save() just refers to the documentation for Pages::save(), and here the explanation of the noHooks option is pretty brief:

noHooks (boolean): Prevent before/after save hooks (default=false), please also use $pages->___save() for call.

It doesn't explain exactly which hookable methods related to saving pages are affected by the noHooks option. But it does make clear that you have to call $pages->___save() with underscores or else hooks to Pages::save() will still fire (which the user probably doesn't want if they are specifying the noHooks option). A similar note exists in the documentation for Pages::saveField().

But the issue is that if you are calling $page->save(['noHooks' => true]) or $page->save('some_field', ['noHooks' => true]) then this method doesn't include the underscore prefix when it calls Pages::save() or Pages::saveField() so some save-related hooks will still fire.

https://github.com/processwire/processwire/blob/f851c638427cf362bddab7f21529c426a13fb2b8/wire/core/Page.php#L2773-L2780

Some thoughts...

1. When the noHooks option is true then Page::save() should call Pages::___save()/Pages::___saveField() with underscores.

2. In the documentation it would be good to include a list of hookable methods that are affected by the noHooks option.

3. The documentation for Page:save() should probably include it's own separate description of the noHooks option rather than just refer to the docs for Pages::save() because two extra methods are involved, namely Pages::save() and Pages::saveField().

Setup/Environment

  • ProcessWire version: 3.0.181

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions