Skip to content

Commit

Permalink
Merge pull request #36 from GSA/feature/DIGITAL-38-migrate-shortcodes
Browse files Browse the repository at this point in the history
Digital-38: migrate shortcodes templates
  • Loading branch information
mattsqd authored Nov 12, 2024
2 parents 16d8b46 + d07abfd commit d96af1e
Show file tree
Hide file tree
Showing 31 changed files with 860 additions and 588 deletions.
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,7 @@ Thumbs.db
# Visual Studio Code
.vscode/*
!.vscode/
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/*.code-snippets
# Local History for Visual Studio Code
.history/
# Built Visual Studio Code Extensions
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"drupal/require_revision_log_message": "^2.0",
"drupal/scheduler": "^2.0",
"drupal/scheduler_content_moderation_integration": "^2.0@beta",
"drupal/twig_field_value": "^2.0",
"drupal/twig_tweak": "^3.3",
"drupal/uswds_templates": "^3.0@dev",
"drupal/vbo_workflow_transition": "1.0.x-dev@dev",
Expand Down
561 changes: 312 additions & 249 deletions composer.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions composer.log
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ ea93266b87251a27fec5df04a3cbd5d0|Matt Poole|feature/DIGITAL-28-shortcode-embed|T
3d742a578663c259c7f20fe529971425|Matt Poole|feature/DIGITAL-45-roles-and-perms|Wed Nov 6 09:56:58 EST 2024|./composer.sh require drupal/views_bulk_operations
1eaf30055796759652004514d15f30d9|christian medders|feature/DIGITAL-31-sitemap-path-auto|Fri Nov 8 14:03:39 EST 2024|./composer.sh require drupal/pathauto:^1.13
58d882c244d0e746a3ad90844a2f361f|christian medders|feature/DIGITAL-31-sitemap-path-auto|Fri Nov 8 14:05:23 EST 2024|./composer.sh require drupal/xmlsitemap:^1.5
94cea224856de297893b41cdaa146ef8|christian medders|feature/DIGITAL-38-migrate-shortcodes|Fri Nov 8 10:32:48 EST 2024|./composer.sh require drupal/twig_field_value
464e1ed27d945bb31dcb7a3d79a19d13|Matt Poole|feature/DIGITAL-38-migrate-shortcodes|Tue Nov 12 16:04:45 UTC 2024|./composer.sh update --lock
3 changes: 3 additions & 0 deletions composer.patches.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
"/project/default_content/issues/3203014: BaseFieldOverride cause inconsistencies during export": "https://www.drupal.org/files/issues/2022-12-13/base_field_override_inconsistencies-3203014-9.patch",
"/project/default_content/issues/3200212: Import should overwrite files": "https://www.drupal.org/files/issues/2024-08-27/default_content-3200212-25.patch"
},
"drupal/embedded_content": {
"Convert html to valid xml": "patches/embedded_content-convert-html-valid-xml.patch"
},
"drupal/maillog": {
"/project/maillog/issues/3176023: Not configurable sender and other issues.": "https://www.drupal.org/files/issues/2024-07-24/maillog-n3176023-9.patch"
}
Expand Down
1 change: 1 addition & 0 deletions config/sync/core.extension.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ module:
text: 0
token: 0
toolbar: 0
twig_field_value: 0
twig_tweak: 0
update: 0
user: 0
Expand Down
18 changes: 18 additions & 0 deletions patches/embedded_content-convert-html-valid-xml.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Index: src/Plugin/Filter/EmbeddedContent.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/Plugin/Filter/EmbeddedContent.php b/src/Plugin/Filter/EmbeddedContent.php
--- a/src/Plugin/Filter/EmbeddedContent.php
+++ b/src/Plugin/Filter/EmbeddedContent.php (date 1731427147463)
@@ -88,6 +88,8 @@
$replacement = $instance->build();
$context = new RenderContext();
$render = $this->renderer->executeInRenderContext($context, fn() => $this->renderer->render($replacement));
+ // Allow &nbsp; in the xml by replacing them with decimal entity.
+ $render = str_replace('&nbsp;', '&#160;', $render);
if (!$context->isEmpty()) {
$bubbleable = $bubbleable->merge($context->pop());
}

40 changes: 30 additions & 10 deletions web/modules/custom/ec_shortcodes/ec_shortcodes.module
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,21 @@ function ec_shortcodes_theme($existing, $type, $theme, $path) {
'kicker' => NULL,
'title' => NULL,
'icon' => NULL,
],
],
'ec_shortcodes_author_bio' => [
'variables' => [
'name' => NULL,
'bio' => NULL,
'text' => NULL,
],
],
'ec_shortcodes_card_policy' => [
'variables' => [
'kicker' => NULL,
'title' => NULL,
'src' => NULL,
'text' => NULL,
],
],
'ec_shortcodes_card_prompt' => [
'variables' => [
'intro' => NULL,
'prompt' => NULL,
'text' => NULL,
'url' => NULL,
],
Expand All @@ -60,25 +57,48 @@ function ec_shortcodes_theme($existing, $type, $theme, $path) {
'rows' => NULL,
],
],
'ec_shortcodes_featured_resource' => [
'ec_shortcodes_featured_resource_ext' => [
'variables' => [
'kicker' => NULL,
'url' => NULL,
'text' => NULL,
'title' => NULL,
'summary' => NULL,
],
],
'ec_shortcodes_highlight' => [
'ec_shortcodes_featured_resource' => [
'variables' => [
'text' => NULL,
'content_reference' => NULL,
],
],
'ec_shortcodes_note' => [
'variables' => [
'heading' => NULL,
'type' => NULL,
'text' => NULL,
'text_override' => NULL,
],
],

'ec_shortcodes_note_join' => [
'variables' => [
'text' => NULL,
],
],
'ec_shortcodes_note_disclaimer' => [
'variables' => [
'heading' => NULL,
],
],
];
}

/**
* Implements hook_preprocess_HOOK().
*/
function ec_shortcodes_preprocess(&$variables, $hook) {
if (in_array($hook, ['ec_shortcodes_accordion', 'ec_shortcodes_card_policy', 'ec_shortcodes_card_prompt',
'ec_shortcodes_note', 'ec_shortcodes_do_dont_table', 'ec_shortcodes_note_join', 'ec_shortcodes_note_disclaimer',
])) {
$variables['theme_path'] = \Drupal::theme()->getActiveTheme()->getPath();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

namespace Drupal\ec_shortcodes\Plugin\EmbeddedContent;

use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\embedded_content\EmbeddedContentInterface;
use Drupal\embedded_content\EmbeddedContentPluginBase;

/**
* Plugin iframes.
*
* @EmbeddedContent(
* id = "ec_shortcodes_featured_resource_ext",
* label = @Translation("Featured Resource - External"),
* description = @Translation("Renders a styled button link."),
* )
*/
class ECShortCodesFeaturedResourceExt extends EmbeddedContentPluginBase implements EmbeddedContentInterface {

use StringTranslationTrait;

/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return [
'kicker' => NULL,
'url' => NULL,
'title' => NULL,
'summary' => NULL,
];
}

/**
* {@inheritdoc}
*/
public function build(): array {
return [
'#theme' => 'ec_shortcodes_featured_resource_ext',
'#kicker' => $this->configuration['kicker'],
'#url' => $this->configuration['url'],
'#title' => $this->configuration['text'],
'#summary' => $this->configuration['summary'],
];
}

/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form['kicker'] = [
'#type' => 'textfield',
'#title' => $this->t('Kicker'),
'#default_value' => $this->configuration['kicker'],
'#required' => TRUE,
];
$form['url'] = [
'#type' => 'url',
'#title' => $this->t('Url'),
'#default_value' => $this->configuration['url'],
'#required' => TRUE,
];
$form['title'] = [
'#type' => 'textfield',
'#title' => $this->t('Text'),
'#default_value' => $this->configuration['title'],
'#required' => TRUE,
];
$form['summary'] = [
'#type' => 'textfield',
'#title' => $this->t('Summary'),
'#default_value' => $this->configuration['summary'],
'#required' => TRUE,
];
return $form;
}

/**
* {@inheritDoc}
*/
public function isInline(): bool {
return FALSE;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function defaultConfiguration() {
'kicker' => NULL,
'title' => NULL,
'icon' => NULL,
'text' => NULL,
];
}

Expand All @@ -40,6 +41,7 @@ public function build(): array {
'#kicker' => $this->configuration['kicker'],
'#title' => $this->configuration['title'],
'#icon' => $this->configuration['icon'],
'#text' => $this->configuration['text'],
];
}

Expand All @@ -50,21 +52,27 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
$form['kicker'] = [
'#type' => 'textfield',
'#title' => $this->t('Kicker'),
'#default_value' => $this->configuration['text'],
'#default_value' => $this->configuration['kicker'],
'#required' => TRUE,
];
$form['title'] = [
'#type' => 'textfield',
'#title' => $this->t('Title'),
'#default_value' => $this->configuration['text'],
'#default_value' => $this->configuration['title'],
'#required' => TRUE,
];
$form['icon'] = [
'#type' => 'media_library',
'#type' => 'textfield',
'#title' => $this->t('Icon'),
'#default_value' => $this->configuration['media_library'],
'#default_value' => $this->configuration['icon'],
'#required' => TRUE,
'#media_types' => ['image'],
];
$form['text'] = [
'#type' => 'text_format',
'#title' => $this->t('Body'),
'#default_value' => $this->configuration['text']['value'] ?? '',
'#format' => 'multiline_inline_html',
'#allowed_formats' => ['multiline_inline_html'],
];

return $form;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function defaultConfiguration() {
'kicker' => NULL,
'title' => NULL,
'src' => NULL,
'text' => NULL,
];
}

Expand All @@ -40,6 +41,8 @@ public function build(): array {
'#kicker' => $this->configuration['kicker'],
'#title' => $this->configuration['title'],
'#src' => $this->configuration['src'],
'#text' => $this->configuration['text'],

];
}

Expand All @@ -50,13 +53,13 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
$form['kicker'] = [
'#type' => 'textfield',
'#title' => $this->t('Kicker'),
'#default_value' => $this->configuration['text'],
'#default_value' => $this->configuration['kicker'],
'#required' => TRUE,
];
$form['title'] = [
'#type' => 'textfield',
'#title' => $this->t('Title'),
'#default_value' => $this->configuration['text'],
'#default_value' => $this->configuration['title'],
'#required' => TRUE,
];
$form['url'] = [
Expand All @@ -65,6 +68,13 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
'#default_value' => $this->configuration['url'],
'#required' => TRUE,
];
$form['text'] = [
'#type' => 'text_format',
'#title' => $this->t('Body'),
'#default_value' => $this->configuration['text']['value'] ?? '',
'#format' => 'multiline_inline_html',
'#allowed_formats' => ['multiline_inline_html'],
];

return $form;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class ECShortcodesCardPrompt extends EmbeddedContentPluginBase implements Embedd
public function defaultConfiguration() {
return [
'intro' => NULL,
'prompt' => NULL,
'text' => NULL,
'url' => NULL,
];
Expand All @@ -38,6 +39,7 @@ public function build(): array {
return [
'#theme' => 'ec_shortcodes_card_prompt',
'#intro' => $this->configuration['intro'],
'#prompt' => $this->configuration['prompt'],
'#text' => $this->configuration['text'],
'#url' => $this->configuration['url'],
];
Expand All @@ -48,9 +50,19 @@ public function build(): array {
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form['intro'] = [
'#type' => 'textfield',
'#type' => 'text_format',
'#title' => $this->t('Intro'),
'#default_value' => $this->configuration['text'],
'#format' => 'multiline_inline_html',
'#allowed_formats' => ['multiline_inline_html'],
'#default_value' => $this->configuration['text']['value'] ?? '',
'#required' => TRUE,
];
$form['prompt'] = [
'#type' => 'text_format',
'#title' => $this->t('Prompt'),
'#format' => 'multiline_inline_html',
'#allowed_formats' => ['multiline_inline_html'],
'#default_value' => $this->configuration['text']['value'] ?? '',
'#required' => TRUE,
];
$form['text'] = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
$form['cite'] = [
'#type' => 'textfield',
'#title' => $this->t('Cite'),
'#default_value' => $this->configuration['text'],
'#default_value' => $this->configuration['cite'],
'#required' => TRUE,
];

Expand Down
Loading

0 comments on commit d96af1e

Please sign in to comment.