Skip to content

Temporarily setting output formatting to true in saveReady prevents proper image deletion #2204

@Toutouwai

Description

@Toutouwai

I understand that output formatting has to be off when a page is saved, but it's unexpected that turning it on then off again prevents proper deletion of images.

This is a simplified example for demonstration. In my real scenario I have a good reason for needing to temporarily enable output formatting for the page at saveReady.

$pages->addHookAfter('saveReady', function(HookEvent $event) {
    /** @var Page $page */
    $page = $event->arguments(0);
    if($page->template == 'basic-page') {
        // Get current output formatting
        $of = $page->of();
        // Temporarily set output formatting to true
        $page->of(true);
        // Do anything that gets the value of an images field
        $images = $page->images;
        // Restore the original output formatting
        $page->of($of);
    }
});

Problem with image deletion:

Image

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