diff --git a/app/helpers/admin/tabbed_nav_helper.rb b/app/helpers/admin/tabbed_nav_helper.rb index 8df95bc6735..6c89a3d0bae 100644 --- a/app/helpers/admin/tabbed_nav_helper.rb +++ b/app/helpers/admin/tabbed_nav_helper.rb @@ -51,6 +51,7 @@ def config_driven_nav_items(edition, current_path, current_tab) current: on_dynamic_tab && current_tab == tab["id"], } end + nav_items.concat(linked_tabs_nav_items(edition, current_path)) end end @@ -216,4 +217,20 @@ def worldwide_organisation_page_nav_items(page, current_path) }, ] end + + def linked_tabs_nav_items(edition, current_path) + edition.type_instance.linked_tabs.map do |tab| + href = href_for_linked_tab(tab, edition) + { label: tab["label"], href:, current: current_path == href } + end + end + + def href_for_linked_tab(tab, edition) + builders = { + "edition_attachments" => -> { admin_edition_attachments_path(edition) }, + "edition_images" => -> { admin_edition_images_path(edition) }, + "edition_features" => -> { features_admin_standard_edition_path(edition, locale: edition.primary_locale) }, + } + builders[tab["linked_to"]]&.call + end end diff --git a/app/models/configurable_document_type.rb b/app/models/configurable_document_type.rb index 589a54ddb47..2ea287b3164 100644 --- a/app/models/configurable_document_type.rb +++ b/app/models/configurable_document_type.rb @@ -113,6 +113,16 @@ def dynamic_tabs end end + def linked_tabs + @linked_tabs ||= @forms.filter_map do |id, form| + { "id" => id, "label" => form["label"], "linked_to" => form["linked_to"] } if form["linked_to"] + end + end + + def has_linked_tab?(tab_key) + linked_tabs.any? { |tab| tab["linked_to"] == tab_key } + end + def schema_for_fields(field_keys) field_keys = field_keys.map(&:to_s) diff --git a/app/models/configurable_document_types/news_story.json b/app/models/configurable_document_types/news_story.json index 64d715226e3..718d3cc7d3a 100644 --- a/app/models/configurable_document_types/news_story.json +++ b/app/models/configurable_document_types/news_story.json @@ -58,6 +58,10 @@ "translatable": false } } + }, + "attachments": { + "label": "Attachments", + "linked_to": "edition_attachments" } }, "schema": { @@ -122,7 +126,6 @@ } }, "send_change_history": true, - "file_attachments_enabled": true, "organisations": null, "backdating_enabled": true, "history_mode_enabled": true, diff --git a/app/presenters/publishing_api/standard_edition_presenter.rb b/app/presenters/publishing_api/standard_edition_presenter.rb index a0b655d8959..a52014d68dd 100644 --- a/app/presenters/publishing_api/standard_edition_presenter.rb +++ b/app/presenters/publishing_api/standard_edition_presenter.rb @@ -43,7 +43,7 @@ def details details = PayloadBuilder::BlockContent.for(item) details.merge!(PayloadBuilder::ChangeHistory.for(item)) if type.settings["send_change_history"] == true details.merge!(PayloadBuilder::PoliticalDetails.for(item)) if type.settings["history_mode_enabled"] == true - details.merge!(PayloadBuilder::Attachments.for(item)) if type.settings["file_attachments_enabled"] == true + details.merge!(PayloadBuilder::Attachments.for(item)) if type.settings["file_attachments_enabled"] == true || type.has_linked_tab?("edition_attachments") details.merge!(PayloadBuilder::EmphasisedOrganisations.for(item)) if item.organisation_association_enabled? details.merge!(PayloadBuilder::StandardEditionImages.for(item)) if type.settings.dig("images", "enabled") details.merge!(PayloadBuilder::Features.for(item)) if type.settings["features_enabled"] == true diff --git a/app/validators/schema_validator.rb b/app/validators/schema_validator.rb index a172ecaf651..1ffe3368805 100644 --- a/app/validators/schema_validator.rb +++ b/app/validators/schema_validator.rb @@ -94,7 +94,11 @@ def required_form_fields end def form_fields - (@document["forms"] || [])&.keys&.flat_map { |key| obj_dig(@document, "fields", ["forms", key]) } + (@document["forms"] || [])&.keys&.flat_map do |key| + next [] if @document.dig("forms", key, "linked_to") # linked tabs have no block content fields, so skip it + + obj_dig(@document, "fields", ["forms", key]) + end end def obj_dig(obj, attr, keys, &visitor) diff --git a/public/configurable-document-type.schema.json b/public/configurable-document-type.schema.json index da1fe622fc8..b089d1ba821 100644 --- a/public/configurable-document-type.schema.json +++ b/public/configurable-document-type.schema.json @@ -243,7 +243,6 @@ }, "additionalProperties": { "type": "object", - "required": ["fields"], "description": "Definition of a group of form fields to group.", "properties": { "dynamic": { @@ -262,8 +261,21 @@ "$ref": "#/$defs/form_field" } } + }, + "linked_to": { + "type": "string", + "description": "Named route this tab links to. Mutually exclusive with fields. Used for tabs whose UI is owned by an existing controller (attachments, features, images).", + "enum": [ + "edition_attachments", + "edition_features", + "edition_images" + ] } - } + }, + "oneOf": [ + { "required": ["fields"] }, + { "required": ["linked_to"] } + ] } }, "presenters": { @@ -471,7 +483,6 @@ "organisations", "backdating_enabled", "history_mode_enabled", - "file_attachments_enabled", "translations_enabled" ] }