Skip to content

Commit

Permalink
DIGITAL-37: Migrate links paragraph templates.
Browse files Browse the repository at this point in the history
Adds paragraph_view_mode module.
Migrate template for featured links field display.
Adds separate templates for default and featured links views of resources.
Updates featured links template with correct markup.
Switch shortcodes to use theme templates for resources.
  • Loading branch information
omerida committed Nov 21, 2024
1 parent d55158d commit 151716b
Show file tree
Hide file tree
Showing 23 changed files with 571 additions and 55 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"drupal/memcache": "^2.5",
"drupal/multivalue_form_element": "@beta",
"drupal/override_node_options": "^2.8",
"drupal/paragraph_view_mode": "^3.1",
"drupal/paragraphs": "^1.18",
"drupal/pathauto": "^1.13",
"drupal/remove_username": "^1.5",
Expand Down
55 changes: 51 additions & 4 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions composer.log
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ ea93266b87251a27fec5df04a3cbd5d0|Matt Poole|feature/DIGITAL-28-shortcode-embed|T
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
e77736ace0d5510b9fc354fdb47813af|Oscar Merida|DIGITAL-37|Tue Nov 19 15:42:44 EST 2024|./composer.sh require drupal/paragraph_view_mode
4 changes: 2 additions & 2 deletions config/sync/core.entity_view_display.node.topics.default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ content:
type: entity_reference_revisions_entity_view
label: hidden
settings:
view_mode: default
view_mode: featured_links
link: ''
third_party_settings: { }
weight: 8
region: content
field_featured_resources:
type: entity_reference_revisions_entity_view
label: hidden
label: above
settings:
view_mode: default
link: ''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ mode: default
content:
field_link:
type: link
label: above
label: hidden
settings:
trim_length: 80
url_only: false
Expand All @@ -28,7 +28,7 @@ content:
region: content
field_summary:
type: text_default
label: above
label: hidden
settings: { }
third_party_settings: { }
weight: 1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
uuid: 7ebac564-9b60-4ebc-bf4f-b1c7e387dc7c
langcode: en
status: true
dependencies:
config:
- core.entity_view_mode.paragraph.featured_links
- field.field.paragraph.external_content.field_link
- field.field.paragraph.external_content.field_summary
- paragraphs.paragraphs_type.external_content
module:
- link
- text
id: paragraph.external_content.featured_links
targetEntityType: paragraph
bundle: external_content
mode: featured_links
content:
field_link:
type: link
label: hidden
settings:
trim_length: 80
url_only: false
url_plain: false
rel: ''
target: ''
third_party_settings: { }
weight: 0
region: content
field_summary:
type: text_default
label: hidden
settings: { }
third_party_settings: { }
weight: 1
region: content
hidden: { }
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ content:
type: entity_reference_revisions_entity_view
label: above
settings:
view_mode: default
view_mode: featured_links
link: ''
third_party_settings: { }
weight: 1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
uuid: 3311037a-b3d8-46b7-9df5-081f4fa9ba2a
langcode: en
status: true
dependencies:
config:
- core.entity_view_mode.paragraph.featured_links
- field.field.paragraph.featured_links.field_links
- field.field.paragraph.featured_links.field_title
- paragraphs.paragraphs_type.featured_links
module:
- entity_reference_revisions
id: paragraph.featured_links.featured_links
targetEntityType: paragraph
bundle: featured_links
mode: featured_links
content:
field_links:
type: entity_reference_revisions_entity_view
label: hidden
settings:
view_mode: featured_links
link: ''
third_party_settings: { }
weight: 1
region: content
field_title:
type: string
label: above
settings:
link_to_entity: false
third_party_settings: { }
weight: 0
region: content
hidden: { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
uuid: 87533f62-27c9-408b-969e-7778bf2d1903
langcode: en
status: true
dependencies:
config:
- core.entity_view_mode.paragraph.featured_links
- field.field.paragraph.internal_content.field_content
- field.field.paragraph.internal_content.field_override_summary
- field.field.paragraph.internal_content.field_override_title
- paragraphs.paragraphs_type.internal_content
module:
- text
id: paragraph.internal_content.featured_links
targetEntityType: paragraph
bundle: internal_content
mode: featured_links
content:
field_content:
type: entity_reference_label
label: above
settings:
link: true
third_party_settings: { }
weight: 0
region: content
field_override_summary:
type: text_default
label: above
settings: { }
third_party_settings: { }
weight: 2
region: content
field_override_title:
type: string
label: above
settings:
link_to_entity: false
third_party_settings: { }
weight: 1
region: content
hidden: { }
11 changes: 11 additions & 0 deletions config/sync/core.entity_view_mode.paragraph.featured_links.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
uuid: 1fc042bc-9ce1-468f-a7f5-c626b6201d31
langcode: en
status: true
dependencies:
module:
- paragraphs
id: paragraph.featured_links
label: 'Featured Links'
description: ''
targetEntityType: paragraph
cache: true
1 change: 1 addition & 0 deletions config/sync/core.extension.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ module:
options: 0
override_node_options: 0
page_cache: 0
paragraph_view_mode: 0
paragraphs_type_permissions: 0
path: 0
path_alias: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function build(): array {
'#theme' => 'ec_shortcodes_featured_resource_ext',
'#kicker' => $this->configuration['kicker'],
'#url' => $this->configuration['url'],
'#title' => $this->configuration['text'],
'#title' => $this->configuration['title'],
'#summary' => $this->configuration['summary'],
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
'#selection_handler' => 'default',
'#required' => TRUE,
'#selection_settings' => [
'target_bundles' => ['authors', 'basic_page', 'community', 'event', 'gide',
'target_bundles' => [
'authors', 'basic_page', 'community', 'event', 'guide',
'news', 'resources', 'services', 'topics',
],
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,11 @@
{# NOT MIGRATED
This should be the partial for featured recources
Kicker should also allow html, but only a single line.
{#
The partial for featured recources:
- Kicker should also allow html, but only a single line.
#}
<div class="dg-featured-resource">
<a href="{{ url }}" class="dg-featured-resource__body">
<div class="dg-featured-resource__text">
<p class="dg-featured-resource__kicker">
{% if kicker %}
{{ kicker }}
{% else %}
{{ 'Featured Resource'|t }}
{% endif %}
</p>
{% if title %}
<h2 class="dg-featured-resource__text-title">
{{ title }}
</h2>
{% endif %}
{% if summary %}
<p class="dg-featured-resource__text-description">
{{ summary }}
</p>
{% endif %}
</div>
</a>
</div>

{{ include("@digital_gov/partials/featured-resource.html.twig", {
'kicker' : kicker ?: '',
'url': url,
'title': title ?: '',
'summary': summary ?: ''
}, with_context = false) }}
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,11 @@
The title and summary should be able to be overriden from the form
#}
{% set summary = drupal_field('field_summary','node', content_reference) | field_value %}
{% set url = path('entity.node.canonical', {'node': content_reference}) %}
{% set title = drupal_field('title','node', content_reference) | field_value %}

<div class="dg-featured-resource">
<a href="{{ path('entity.node.canonical', {'node': content_reference}) }}"
class="dg-featured-resource__body">
<div class="dg-featured-resource__text">
<p class="dg-featured-resource__kicker">
{{ 'Featured Resource'|t }}
</p>
<h2 class="dg-featured-resource__text-title">
{{ drupal_field('title','node', content_reference) | field_value }}
</h2>
{% if summary %}
<p class="dg-featured-resource__text-description">
{{ summary }}
</p>
{% endif %}
</div>
</a>
</div>
{{ include("@digital_gov/partials/featured-resource.html.twig", {
'title': title ?: '',
'url': url,
'summary': summary ?: ''
}, with_context = false) }}
41 changes: 41 additions & 0 deletions web/themes/custom/digital_gov/digital_gov.theme
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,44 @@ function digital_gov_preprocess_menu(&$variables, $hook) {
}
}
}

/**
* Implements hook_preprocess_paragraph().
*/
function digital_gov_preprocess_paragraph(&$variables) {
$paragraph = $variables['paragraph'];
$static_path = '/' . \Drupal::theme()->getActiveTheme()->getPath() . '/static';
switch ($paragraph->bundle()) {
case 'external_content':
$variables['logo_source'] = digital_gov_get_logo_source($paragraph->field_link[0]->uri, $static_path);
break;

case 'internal_content':
$variables['logo_source'] = digital_gov_get_logo_source('http://digital.gov', $static_path);
break;
}
}

/**
* Return the logo image to use for a given host/domain.
*/
function digital_gov_get_logo_source(string $uri, string $static_path): string {
$host = parse_url($uri, PHP_URL_HOST);

if (str_ends_with($host, 'digital.gov')) {
return $static_path . '/digitalgov/img/digit-50.png';
}

// This is not a foolproof way to get domains.
$domain = preg_replace('#^(?:.+?\\.)+(.+?\\.(?:co\\.uk|com|net|org|gov|mil|io))#', '$1', $host);

// The hugo templates looked for a field named 'source' that indicates
// a local hi-res logo to use. For example, justice.gov had
// a logos/doj-icon.png/ to use. Are we migrating this?
$logo_url = $static_path . '/digitalgov/logos/' . $domain . '-icon.png';
if (file_exists(DRUPAL_ROOT . $logo_url)) {
return $logo_url;
}

return 'https://www.google.com/s2/favicons?domain=' . $domain;
}
Loading

0 comments on commit 151716b

Please sign in to comment.