One gallery in several articles: order, captions and permission to reuse

Reuse a photograph while keeping separate ordering, localized text and permission for each context.

Different frames represent separate contexts for using an image.
Different frames represent separate contexts for using an image.

Two articles need the same photograph of a greenhouse. The first explains a repair: the image follows a list of tools and carries the caption “Greenhouse before repairs.” The second describes a visitor route: the photograph closes the collection, and its caption explains where the walk begins. If one caption is stored directly against the file, editing the second article unexpectedly changes the first.

This problem appears before choosing an image format. We need to decide who owns the order, the text and permission to display the image. We will build a separate teaching model in which one media asset has two independent memberships. It describes metadata and selection rules; it does not process photographs, uploads or network delivery.

What are we actually reusing?

“One gallery in several articles” allows two different designs. Articles can reference a shared live album: changing its order and captions affects every article immediately. That is useful when every appearance should use the same editorial collection. However, each article has no independent caption until another contextual layer is introduced.

Alternatively, we can reuse the assets while keeping collections and memberships separate. We choose that approach for the exercise. The first article's gallery and the second article's gallery have their own identities. They reference the same photograph but do not share membership order or text. Copying a collection would create new membership records, not new photograph bytes.

If a product needs a shared live album with exceptions for particular publications, those exceptions need their own design: which value wins a conflict, how new album members propagate, and when a local edit stops inheriting the shared value. The prepared model does not claim to implement that mechanism.

Three owners of data

The media asset owns the image's shared identity. In this exercise it contains only a technical title and a placeholder path. Source revisions, derivative sizes and byte replacement remain the responsibility of a separate media model. Changing one gallery's caption does not create a new photograph.

The gallery defines the collection's context: its article and site. A membership links a particular gallery to a particular asset and owns a position and localized text. Its own identifier makes it possible to edit or remove the relationship without deleting the image.

Data Owner in the exercise Effect of a change
Placeholder image path Asset Shared by its permitted uses
Article and site of the collection Gallery Define the reading context
Position, caption and alternative text Membership Change only the relevant collection
Permission for a site to use an image Separate grant record Checked before building the response

Permission is deliberately separate from the relationship. The existence of a membership does not mean that it may be displayed on every site.

Two collections, one photograph

Synthetic asset A1 is the greenhouse photograph. Membership M1 belongs to gallery G1 on the first site and has position 2. Membership M2 belongs to G2 on the second site and has position 8. Their captions differ even though their asset_id is identical.

Each gallery contains another photograph so that the exercise can check an actual list order. In G1, membership M3 at position 1 precedes M1. In G2, membership M4 at position 3 precedes M2. The expected sequences are M3, M1 and M4, M2. These expectations were recorded in advance and matched the actual local run.

Both sites have an explicit grant for A1. A third site has no such grant. Even if an erroneous reference to A1 enters that site's own gallery, a read must return neither that membership nor the image title or path. This case ensures that the check covers more than simply requesting somebody else's gallery.

Position needs a second key

The exercise orders by ascending position and then by membership identifier when positions are equal. This is the example's explicit policy; a product may choose another direction. If two memberships receive position 3, their result still has a defined order. Position alone cannot provide that.

Moving M2 to position 0 changes the second gallery's order to M2, M4. The first gallery remains unaffected. This independence also matters in the editing interface: a command should name the membership and its gallery instead of globally changing “the photograph's position.”

The current example reads a small list in the memory of one process. It does not promise a stable traversal of several pages while concurrent reordering takes place. A persisted collection needs separate rules for concurrent edits and, where appropriate, a context version. A deterministic order for one read does not replace those rules.

Caption language and image purpose

The membership stores a caption and alternative text separately. W3C WAI explains that a text alternative depends on the image's information or function in its particular context. A caption may discuss a repair stage while alt conveys relevant image content. One field should not automatically be copied into the other.

Each field in the exercise follows a simple selection order: the requested locale, an explicitly permitted fallback locale, then a missing value. The absent Russian text for M2 may therefore use Ukrainian if the call explicitly permits uk. The response also retains the actual language selected; otherwise the interface may present fallback text as a completed translation.

An empty string does not mean absence. For M4, the English caption and alt are deliberately empty: this is the declared decorative variant of that teaching context. Ukrainian fallback text must not overwrite it. By comparison, null means that text is missing. The renderer must decide whether the usage can be displayed; the model does not automatically turn unknown alternative text into a decorative choice.

The file's general description is not an implicit final fallback. That keeps hidden decisions out of the exercise. If a product inherits shared asset text, that level should be added to the documented selection order and checked separately.

Check permission before building the card

A read first checks whether the gallery belongs to the current site. A foreign gallery and an unknown gallery return the same unavailable result. It then checks the asset grant for each membership. Only afterwards may the card contain the membership identifier, title, path and localized fields.

The application must supply a trusted site context to this function. Accepting an arbitrary site_id from a request and calling it the current site would remove the boundary. Editor permission to change the collection is a separate requirement. Symfony allows reusable authorization rules to be placed in a voter; the teaching class itself implements neither user login nor an HTTP endpoint.

A technical grant record also needs an origin: who established it and on what basis. The exercise starts with predetermined synthetic grants and does not determine the actual terms for using a photograph. It shows where an established decision must affect the response.

After a grant is revoked, the second site's next read should omit M2; the first site's M1 remains. A persisted system must additionally coordinate caches and file delivery. Deleting a grant record alone does not revoke URLs already issued or bytes already downloaded. The model never requests its placeholder paths.

Remove the membership, retain the photograph

Removing M1 detaches the image from the first gallery. M2, its caption and asset A1 remain. Physical file cleanup is another operation, requiring a complete map of uses and its own policy. The disappearance of one relationship is insufficient grounds for it.

The exercise rejects adding the same asset to the same gallery twice. Another gallery may use it when a grant exists. If a product intentionally allows the same photograph to appear twice in one album, that uniqueness rule no longer fits: the editorial occurrences must be distinguished explicitly. This is a content decision, not an accidental consequence of a table structure.

Checking behavior after integration

The actual PHP run compared output against independently frozen literal DTOs: all 14 named scenarios passed. Checks confirmed two complete projections, M2 ru→uk fallback, empty text without substitution, null for foreign/missing galleries, [] for an allowed G3 without an asset grant, revocation, unlink/reorder isolation, ties, no implicit fallback, foreign mutation refusal, locale rejection, and duplicate membership refusal. The runner does not instrument a separate native assertion count; none is invented. A separate PHPUnit adapter passed as 1 test with 4 assertions, checking exact case names and the native summary. This is the same set of 14 scenarios, not 28 distinct ones. PHP 8.5.12 and PHPUnit 13.4.6 were used; the canonical suite requires PHP 8.4.1. No actual HTTP/DB/browser/delivery/cache/editor authorization/concurrency evidence is established.

The example is added to one existing teaching application through new classes, fixtures and a verification script. It needs neither another skeleton nor replacement of earlier routes. The independent scenario has been executed. Selection of the trusted site, editor authorization, text escaping and HTTP presentation behavior need their own subsequent checks.

The useful editorial outcome is specific: a photograph can remain shared while the context of each use has an owner. A caption change, reorder or individual grant then affects a defined set of appearances. That set should be named and checked before adding a button labeled “use in another article.”

  1. Article Engineering An image as a separate asset: identity, originals, and derivatives
  2. Article Engineering One cover for different screens: cropping and responsive delivery
  3. Architecture Product catalog and journal: where reuse must end

A project by the author · Weather Solution200

After reading, a look outside.

Temperature, rain and wind in your city. Check the forecast and plan the hours ahead.

Check the forecast
Next article