Keep default Open Graph media replaceable when defaults are defined across several calls

Merged
MR
10d ago
+22-2

When the defaults layer is built with more than one Head::defaults() call and a later call adds Open Graph media, the merged Open Graph builder stops being marked as defaults. A page that sets its own image then gets both images rendered instead of having its own replace the default one:

Head::defaults(fn (HeadBuilder $head) => $head->og(siteName: 'Acme'));
Head::defaults(fn (HeadBuilder $head) => $head->ogImage('https://example.com/brand.png'));

Head::ogImage('https://example.com/product.jpg');

// <meta property="og:image" content="https://example.com/brand.png">
// <meta property="og:image" content="https://example.com/product.jpg">

Link previews usually take the first og:image, so the page is shared with the brand image instead of its own. A single Head::defaults() call works as expected; the difference comes from OpenGraph::overlayOn(), which marks the overlaid media as non-default whenever the overlay has media, even when the overlay itself belongs to the defaults layer.

This PR keeps the media a replaceable fallback while all of it comes from the defaults layer. Page-level media merges exactly as before and a single defaults() call behaves the same. The only change is that splitting the defaults across several calls, for example across service providers, no longer changes how page media overrides them. A test covers the case.