Skip to content

Freeware

When a Freeware item is published or updated in Sanity, the system fetches type-specific fields in addition to the general variables. Freeware is the most complex resource type because it includes form handling and download logic needed to render the download modal in the Resource Center.

Source file: algolia/custom_actions/types/getResourcesData.js


FieldSourceDescription
dateprops.draft?.attributes?.datePublication date
freeware_formHero configurationComplete form configuration object for the download modal

The freeware form data is extracted from the hero section of the Sanity document. The hero determines whether a form or a button is displayed, and what happens after submission.

FieldDescription
form_scriptThe form embed script from the forms document
form_ty_messageThank-you message displayed after form submission
form_has_downloadWhether the form triggers a file download
form_download_typeDownload type (file or external)
form_modal_download_fileURL of the downloadable file (resolved from asset reference)
form_fileRaw file reference
form_external_referenceExternal URL for non-file downloads
form_has_redirectWhether the form redirects after submission
form_redirectRedirect configuration (target page slug, option)

date = props.draft?.attributes?.date;

The system reads the first hero of the document to determine if a form or button is included:

var hero = props?.draft?.heros[0];
var include_form = hero?.include_form
var include_button = hero?.include_button
var form = include_form
? hero.form_script?._ref
: include_button
? hero.hero_button?.modal_form_script?._ref
: '';

If the download type is file, the system resolves the file asset URL from Sanity:

if (form_download_type == 'file' && form_modal_download_file) {
var queryForm = `*[_id == "${form_modal_download_file?.asset?._ref}"][0]`
await client.fetch(queryForm).then((form) => {
form_modal_download_file = form.url;
})
}

If the form has a redirect to an internal page, the system resolves the page slug:

if (form_has_redirect && form_redirect.option == 'target_self' && form_redirect?.pages) {
var queryForm = `*[_id == "${form_redirect.pages?._ref}"][0]{'slug': attributes.slug}`;
await client.fetch(queryForm).then((form) => {
form_redirect.slug = form.slug;
})
}

The form embed script and thank-you message are fetched from the forms document type:

var queryForm = `*[_type == "forms" && _id == "${form}"][0]{
'script': text,
'thank_you_message': thank_you_message
}`
await client.fetch(queryForm).then((form) => {
form_script = form?.script
form_ty_message = form?.thank_you_message
})

All form-related fields are grouped into a single freeware_form object:

freeware_form = {
form_script,
form_ty_message,
form_has_download,
form_download_type,
form_modal_download_file,
form_file,
form_external_reference,
form_has_redirect,
form_redirect,
}

This object is included in the Algolia record so the Resource Center can render the download modal without additional API calls.