Skip to main content

GravityKit\GravityMigrate\Media\ImageChoiceImages

Walks a form definition's Image Choice fields and rewrites each choice's image.

A choice stores two things about its image: file_url, which is what the field renders, and attachment_id, which \GF_Field_Image_Choice uses to regenerate the image's sizes. Both belong to the source site. Left alone after a migration the URL renders from the old site for as long as it stays up, and the id names whatever attachment happens to hold that number here -- somebody else's media, whose sizes Gravity Forms then regenerates.

The id is decided for every choice before anything else that choice carries is read, and is written back only from what the import returned. file_url and attachment_id arrive as independent values inside the bundle -- a choice can carry a number and no URL at all, so reading the URL first leaves exactly that shape untouched.

Since: %ver%

Source: src/Media/ImageChoiceImages.php:26

Details

  • Kind: class
  • Namespace: GravityKit\GravityMigrate\Media

Methods

MethodDescription
rewrite()Rewrites every Image Choice image in a form definition.

Method Reference

rewrite()

public static function rewrite( array $display_meta, callable $import, ?callable $on_failure=null, bool $clear_stale_ids=true ): array

Rewrites every Image Choice image in a form definition.

Parameters

NameTypeDefaultDescription
$display_metaarrayThe form definition.
$importcallableTakes the source URL; returns [ 'url' => string, 'attachment_id' => int|string ] when the image came across, or null when it did not.
$on_failurecallable | nullnullTold the URL of each image that did not come across.
$clear_stale_idsbooltrueWhether the id the definition arrived with is meaningless on this site. Pass false only when the definition is known, from something other than the bundle, to have come from this same site -- there the id still resolves and clearing it discards a working image.

Returns

  • array — The form definition, with its Image Choice images repointed.

Since: %ver%

Source: src/Media/ImageChoiceImages.php:47