From 6b15e5c40a1fd7d70e56a4bd91a81b194aa76f31 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Mon, 7 Jul 2025 22:22:37 +0100 Subject: [PATCH] Add the subscription form below the body content Add the subscription form below the body content for daily email nodes. --- ..._view_display.node.daily_email.default.yml | 47 +++++++++++++++++++ .../src/Form/KitSubscriptionForm.php | 13 +++++ .../templates/node--daily-email.html.twig | 2 +- 3 files changed, 61 insertions(+), 1 deletion(-) diff --git a/config/sync/core.entity_view_display.node.daily_email.default.yml b/config/sync/core.entity_view_display.node.daily_email.default.yml index af7514181..d878152fd 100644 --- a/config/sync/core.entity_view_display.node.daily_email.default.yml +++ b/config/sync/core.entity_view_display.node.daily_email.default.yml @@ -7,8 +7,55 @@ dependencies: - field.field.node.daily_email.field_daily_email_cta - node.type.daily_email module: + - layout_builder + - layout_discovery + - opd_daily_emails - text - user +third_party_settings: + layout_builder: + enabled: true + allow_custom: false + sections: + - + layout_id: layout_onecol + layout_settings: + label: '' + components: + 5f64dbd7-4d0e-4ac0-ae42-a1698b66931a: + uuid: 5f64dbd7-4d0e-4ac0-ae42-a1698b66931a + region: content + configuration: + id: 'field_block:node:daily_email:body' + label_display: '0' + context_mapping: + entity: layout_builder.entity + formatter: + type: text_default + label: hidden + settings: { } + third_party_settings: { } + weight: 0 + additional: { } + third_party_settings: { } + - + layout_id: layout_onecol + layout_settings: + label: '' + context_mapping: { } + components: + fe7184b1-4b65-4fc2-bb42-3bdbb81287c7: + uuid: fe7184b1-4b65-4fc2-bb42-3bdbb81287c7 + region: content + configuration: + id: opd_daily_emails_kit_subscription_block + label: 'Was this interesting?' + label_display: visible + provider: opd_daily_emails + context_mapping: { } + weight: 0 + additional: { } + third_party_settings: { } id: node.daily_email.default targetEntityType: node bundle: daily_email diff --git a/modules/opd_daily_emails/src/Form/KitSubscriptionForm.php b/modules/opd_daily_emails/src/Form/KitSubscriptionForm.php index ffa669f63..5d7d2e179 100644 --- a/modules/opd_daily_emails/src/Form/KitSubscriptionForm.php +++ b/modules/opd_daily_emails/src/Form/KitSubscriptionForm.php @@ -20,6 +20,19 @@ final class KitSubscriptionForm extends FormBase { * @return array */ public function buildForm(array $form, FormStateInterface $formState): array { + // TODO: refactor to a custom theme function. + // TODO: make this optional. I may not want the intro text on every form - especially when two are on the same page. + $form['intro'] = [ + '#type' => 'html_tag', + '#tag' => 'div', + '#attributes' => [ + 'class' => 'prose prose-p:text-black prose-a:font-light prose-a:text-blue-primary prose-p:text-lg prose-blockquote:border-blue-primary dark:marker:text-white prose-li:my-1 prose-li:text-lg prose-figcaption:text-white prose-li:text-black marker:text-black dark:prose-p:text-white dark:prose-invert dark:prose-a:text-blue-400 dark:prose-blockquote:border-blue-400 dark:prose-li:text-white prose-a:hover:no-underline prose-h2:text-xl prose-code:font-normal prose-h2:mb-4 prose-ul:my-3 dark:prose-hr:border-neutral-400 prose-code:before:content-[\'\'] prose-code:after:content-[\'\'] prose-pre:bg-neutral-200 prose-pre:text-black prose-pre:rounded-none prose-code:bg-neutral-200', + 'style' => 'margin-bottom: 1rem;', + ], + ]; + + $form['intro']['text']['#markup'] = '

' . t('Subscribe to my daily newsletter for software professionals on software development and delivery, Drupal, DevOps, community, and open-source.') . '

'; + $form['email_address'] = [ '#placeholder' => 'me@example.com', '#title' => $this->t('What is your best email address?'), diff --git a/themes/opdavies/templates/node--daily-email.html.twig b/themes/opdavies/templates/node--daily-email.html.twig index bb54e1f8c..135ec5a70 100644 --- a/themes/opdavies/templates/node--daily-email.html.twig +++ b/themes/opdavies/templates/node--daily-email.html.twig @@ -77,7 +77,7 @@ {% endif %} - + {{ content }}