Skip to content

Commit 46309bb

Browse files
GDSNewtChrisBAshton
authored andcommitted
WIP: Social media links
1 parent 9e4822b commit 46309bb

6 files changed

Lines changed: 83 additions & 3 deletions

File tree

app/models/configurable_content_blocks/factory.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ def build_block(block)
99
"default_string" => ->(_page) { ConfigurableContentBlocks::DefaultString.new },
1010
"govspeak" => ->(page) { ConfigurableContentBlocks::Govspeak.new(page.images, page.attachments) },
1111
"default_date" => ->(_page) { ConfigurableContentBlocks::DefaultDate.new },
12+
"social_media_service_select" => ->(_page) { ConfigurableContentBlocks::SocialMediaServiceSelect.new },
1213
"image_select" => ->(page) { ConfigurableContentBlocks::ImageSelect.new(page.valid_images) },
1314
"lead_image_select" => ->(page) { ConfigurableContentBlocks::LeadImageSelect.new(page.valid_lead_images, default_lead_image: page.default_lead_image, placeholder_image_url: page.placeholder_image_url) },
1415
"default_object" => ->(_page) { ConfigurableContentBlocks::DefaultObject.new(self) },
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module ConfigurableContentBlocks
2+
class SocialMediaServiceSelect
3+
attr_reader :services
4+
5+
def initialize
6+
@services = SocialMediaService.all
7+
end
8+
9+
def to_partial_path
10+
"admin/configurable_content_blocks/social_media_service_select"
11+
end
12+
end
13+
end

app/models/configurable_document_types/topical_event.json

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,20 @@
2323
"block": "default_date"
2424
}
2525
}
26+
},
27+
"social_media_links": {
28+
"title": "Social media accounts",
29+
"block": "default_array",
30+
"fields": {
31+
"social_media_service_id": {
32+
"title": "Service",
33+
"block": "social_media_service_select"
34+
},
35+
"url": {
36+
"title": "URL",
37+
"block": "default_string"
38+
}
39+
}
2640
}
2741
}
2842
}
@@ -37,6 +51,17 @@
3751
},
3852
"end_date": {
3953
"type": "date"
54+
},
55+
"social_media_links": {
56+
"type": "array",
57+
"attributes": {
58+
"social_media_service_id": {
59+
"type": "integer"
60+
},
61+
"url": {
62+
"type": "string"
63+
}
64+
}
4065
}
4166
},
4267
"validations": {
@@ -67,7 +92,8 @@
6792
"publishing_api": {
6893
"body": "govspeak",
6994
"start_date": "rfc3339_date",
70-
"end_date": "rfc3339_date"
95+
"end_date": "rfc3339_date",
96+
"social_media_links": "social_media_links"
7197
}
7298
},
7399
"associations": [

app/presenters/publishing_api/payload_builder/block_content.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,21 @@ def lead_image(attribute)
8080
url: item.placeholder_image_url,
8181
}
8282
end
83+
84+
def social_media_links(attribute)
85+
content = item.block_content&.public_send(attribute)
86+
return [] if content.blank?
87+
88+
content.map do |item|
89+
# `item` looks something like `{"url"=>"foo", "social_media_service_id"=>"3"}`
90+
service = SocialMediaService.find(item["social_media_service_id"].to_i)
91+
{
92+
title: service.name,
93+
service_type: service.name.parameterize, # "Google Plus" => "google-plus"
94+
href: item["url"],
95+
}
96+
end
97+
end
8398
end
8499
end
85100
end
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<% required = required || false %>
2+
<% translated_content = translated_content || nil %>
3+
<% select_options = [
4+
{
5+
text: "No social media service selected",
6+
value: "",
7+
},
8+
] + social_media_service_select.services.map do |service|
9+
{
10+
text: service.name,
11+
value: service.id,
12+
selected: service.id == (translated_content || content).to_i,
13+
}
14+
end %>
15+
<% errors = errors || [] %>
16+
<%= render "govuk_publishing_components/components/select", {
17+
id: path.form_control_id,
18+
label: schema["title"] + (required ? " (required)" : ""),
19+
name: path.form_control_name,
20+
options: select_options,
21+
hint: schema["description"],
22+
error_items: errors_for(errors, path.validation_error_attribute.to_sym),
23+
} %>

public/configurable-document-type.schema.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@
5353
"default_string",
5454
"govspeak",
5555
"image_select",
56-
"lead_image_select"
56+
"lead_image_select",
57+
"social_media_service_select"
5758
]
5859
},
5960
"fields": {
@@ -201,7 +202,8 @@
201202
"rfc3339_date",
202203
"image",
203204
"lead_image",
204-
"string"
205+
"string",
206+
"social_media_links"
205207
]
206208
}
207209
},

0 commit comments

Comments
 (0)