Wordpress - Set default image link target in Gutenberg image block

Using the filter blocks.registerBlockType we can alter block registration settings. We simply need to target the core/image block and modify the default value for the attribute linkDestination which is none by default.

function modifyLinkDestinationDefault(settings, name) {
    if (name !== "core/image") {
        return settings;
    }

    settings.attributes.linkDestination.default = "media";

    return settings;
}

wp.hooks.addFilter(
    "blocks.registerBlockType",
    "my-plugin/modify-linkDestination-default",
    modifyLinkDestinationDefault
);