Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

content modelling/865 fields in embed codes #17

Merged
merged 7 commits into from
Feb 4, 2025

Conversation

Harriethw
Copy link
Contributor

@Harriethw Harriethw commented Jan 31, 2025

https://trello.com/c/UWUx0rCF/865-allow-individual-fields-to-be-embedded-with-embed-code

We want to enable users to pass field names via a Content Blocks embed code, like this:

{{embed:content_block_email_address:2593f06c-b7c8-4173-9a47-09d9bdd767ef/field_name/another_field}}

The field names currently can only be keys within a block's details json blob.

This PR introduces:

  1. requiring the embed_code to be passed to a ContentBlock when presenting it, because we now need to know the content of the code to determine whether a field is required.
  2. changing the regex match used to find an embed code to include an optional substring containing field names.

I'm using the test type of postal address so we can see it working IRL.

next steps:

  1. The breaking changes are fixed in Publishing API here to show how the embed code can be retrieved and then passed in content modelling/865 fields in embed codes publishing-api#3117
  2. If we are happy with this approach, we should introduce some error handling and throw Sentry errors if an incorrect field name is used so we can track how often/if that happens.

This repo is owned by the content modelling team. Please let us know in #govuk-publishing-content-modelling-dev when you raise any PRs.

@Harriethw Harriethw force-pushed the content-modelling/865-fields-in-embed-codes branch from f3d635c to c958018 Compare January 31, 2025 17:52
#
# @return [string] A representation of the content block to be wrapped in the base_tag in
# {#content}
def content
if field_names.present?
content_for_fields
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm not sure the base presenter here should be processing field names, or if it should always only return title, but this was only way to test method to dig into nested fields worked without create a whole new type of block 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the way I planned it originally was to have a presenter for each block type, but if we're having a more field-based approach, this might not be the right move. I think this is fine for now - as we experiment, we can tidy this up a bit more.

@Harriethw Harriethw changed the title content modelling/865 fields in embed codes WIP content modelling/865 fields in embed codes Jan 31, 2025
we will need to use the embed code in order to see if
a field name has been passed with it. Because a
ContentBlockReference is returning the embed code
already, which is what our consumer the Publishing API
uses to assess embeds, then it will be easy to just pass
it back when creating a new Content Block
we want to pass fields in in this format:

{{embed:content_block_email_address:2593f06c-b7c8-4173-9a47-09d9bdd767ef/field_name/another_field}}

so the regex query has to account for an optional `/` and then
any number of characters before the closing `}}`
this adds a `content_for_fields` base method as
default for all blocks - this will allow us to have a shared
default handling of fields for block types.
this is a placeholder block type to help us
test whether we can use field names in an
embed code.
@Harriethw Harriethw force-pushed the content-modelling/865-fields-in-embed-codes branch from 7adeb31 to 5240941 Compare February 3, 2025 14:53
@Harriethw Harriethw marked this pull request as ready for review February 3, 2025 16:50
@Harriethw Harriethw requested a review from pezholio February 3, 2025 16:50
@Harriethw Harriethw changed the title WIP content modelling/865 fields in embed codes content modelling/865 fields in embed codes Feb 3, 2025
Copy link
Contributor

@pezholio pezholio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - just one tiny suggestion

<span
class="content-embed content-embed__something"
data-content-block=""
data-document-type="something"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should add the field name to the data attributes? Might help with previewing

#
# @return [string] A representation of the content block to be wrapped in the base_tag in
# {#content}
def content
if field_names.present?
content_for_fields
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the way I planned it originally was to have a presenter for each block type, but if we're having a more field-based approach, this might not be the right move. I think this is fine for now - as we experiment, we can tidy this up a bit more.

@Harriethw Harriethw force-pushed the content-modelling/865-fields-in-embed-codes branch from 09b45ac to 67e0a7c Compare February 4, 2025 11:25
@@ -29,12 +29,15 @@ def render
content_block: "",
document_type: content_block.document_type,
content_id: content_block.content_id,
field_names: field_names.to_s,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be better to join this with a comma, rather than presenting it as an array

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good shout, done!

to make it easier to find and track the blocks
in published host documents.
@Harriethw Harriethw force-pushed the content-modelling/865-fields-in-embed-codes branch from 67e0a7c to c0288f5 Compare February 4, 2025 12:14
@Harriethw Harriethw merged commit f3da520 into main Feb 4, 2025
13 checks passed
@Harriethw Harriethw deleted the content-modelling/865-fields-in-embed-codes branch February 4, 2025 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants