Skip to content

Commit

Permalink
DIGITAL-30: Migrate node templates
Browse files Browse the repository at this point in the history
- Adds template for news, authors and related field templates.
- Move authors markup to re-usable partial that other templates can call.
- Add community page template
- Adds event template
- Adds stage templates for events and share tools template
- Adds stub for topics content type
- Show summary and legislation card on topic page.

- Add archived content warning to news page.
- Add created date to news meta div
- Add page header to news and events pages.
- Add breadcrumb to event and news nodes
- Add breadcrumb and header to community template.
- Tagging not-migrated sections in topics template
- Tagging not-migrated sections in communities template
  • Loading branch information
omerida committed Nov 13, 2024
1 parent d96af1e commit 93ab993
Show file tree
Hide file tree
Showing 27 changed files with 1,702 additions and 19 deletions.
31 changes: 19 additions & 12 deletions config/sync/core.entity_form_display.node.authors.default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ third_party_settings:
label: 'Social Media'
region: content
parent_name: ''
weight: 20
weight: 19
format_type: details
format_settings:
classes: ''
Expand Down Expand Up @@ -73,39 +73,39 @@ content:
third_party_settings: { }
field_agency_acronym:
type: string_textfield
weight: 15
weight: 14
region: content
settings:
size: 60
placeholder: ''
third_party_settings: { }
field_agency_full_name:
type: string_textfield
weight: 14
weight: 13
region: content
settings:
size: 60
placeholder: ''
third_party_settings: { }
field_bio:
type: text_textfield
weight: 17
weight: 16
region: content
settings:
size: 60
placeholder: ''
third_party_settings: { }
field_bio_url:
type: link_default
weight: 18
weight: 17
region: content
settings:
placeholder_url: ''
placeholder_title: ''
third_party_settings: { }
field_email:
type: email_default
weight: 12
weight: 11
region: content
settings:
placeholder: ''
Expand All @@ -121,7 +121,7 @@ content:
third_party_settings: { }
field_first_name:
type: text_textfield
weight: 9
weight: 8
region: content
settings:
size: 60
Expand All @@ -145,7 +145,7 @@ content:
third_party_settings: { }
field_last_name:
type: text_textfield
weight: 10
weight: 9
region: content
settings:
size: 60
Expand All @@ -161,23 +161,31 @@ content:
third_party_settings: { }
field_location:
type: string_textfield
weight: 16
weight: 15
region: content
settings:
size: 60
placeholder: ''
third_party_settings: { }
field_pronouns:
type: string_textfield
weight: 11
weight: 10
region: content
settings:
size: 60
placeholder: ''
third_party_settings: { }
field_slug:
type: string_textfield
weight: 18
region: content
settings:
size: 60
placeholder: ''
third_party_settings: { }
field_summary:
type: text_textfield
weight: 13
weight: 12
region: content
settings:
size: 60
Expand Down Expand Up @@ -251,7 +259,6 @@ content:
placeholder: ''
third_party_settings: { }
hidden:
field_slug: true
publish_on: true
publish_state: true
unpublish_on: true
Expand Down
9 changes: 8 additions & 1 deletion config/sync/core.entity_form_display.node.news.default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ content:
settings:
media_types: { }
third_party_settings: { }
field_slug:
type: string_textfield
weight: 14
region: content
settings:
size: 60
placeholder: ''
third_party_settings: { }
field_summary:
type: text_textfield
weight: 3
Expand Down Expand Up @@ -167,7 +175,6 @@ content:
removed_reference: optional
third_party_settings: { }
hidden:
field_slug: true
promote: true
publish_on: true
publish_state: true
Expand Down
13 changes: 10 additions & 3 deletions config/sync/core.entity_form_display.node.topics.default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ content:
third_party_settings: { }
field_featured_links:
type: paragraphs
weight: 28
weight: 13
region: content
settings:
title: Paragraph
Expand All @@ -90,7 +90,7 @@ content:
third_party_settings: { }
field_featured_resources:
type: paragraphs
weight: 26
weight: 12
region: content
settings:
title: Paragraph
Expand Down Expand Up @@ -130,6 +130,14 @@ content:
settings:
media_types: { }
third_party_settings: { }
field_slug:
type: string_textfield
weight: 14
region: content
settings:
size: 60
placeholder: ''
third_party_settings: { }
field_summary:
type: text_textfield
weight: 2
Expand Down Expand Up @@ -184,7 +192,6 @@ content:
removed_reference: optional
third_party_settings: { }
hidden:
field_slug: true
promote: true
publish_on: true
publish_state: true
Expand Down
7 changes: 4 additions & 3 deletions config/sync/core.entity_view_display.node.news.default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ content:
weight: 101
region: content
field_authors:
type: entity_reference_label
label: above
type: entity_reference_entity_view
label: hidden
settings:
view_mode: default
link: true
third_party_settings: { }
weight: 126
Expand Down Expand Up @@ -96,7 +97,7 @@ content:
region: content
field_topics:
type: entity_reference_label
label: above
label: hidden
settings:
link: true
third_party_settings: { }
Expand Down
73 changes: 73 additions & 0 deletions web/themes/custom/digital_gov/digital_gov.theme
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

declare(strict_types=1);

use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\Core\Template\Attribute;

/**
Expand All @@ -32,7 +33,79 @@ function digital_gov_preprocess_page(array &$variables): void {
* Implements hook_preprocess_HOOK() for node.html.twig.
*/
function digital_gov_preprocess_node(array &$variables): void {
$variables['attributes']['class'] = 'grid-container-desktop';
$created = DrupalDateTime::createFromTimestamp($variables['node']->getCreatedTime());
$variables['created'] = $created->format('M j, Y');

switch ($variables['node']->bundle()) {
case 'news':
$before_date = new DrupalDateTime('5 years ago');
$variables['show_archive_warning'] = $created->getPhpDateTime() <= $before_date->getPhpDateTime();
break;

case 'event':
$now = new DrupalDateTime();
$startDate = $variables['node']->field_start_date->date;
$variables['start_date'] = $startDate->format('l, F j, Y', ['timezone' => date_default_timezone_get()]);
$variables['start_time'] = $startDate->format('g:i A', ['timezone' => date_default_timezone_get()]);
$variables['is_future_event'] = $startDate->getPhpDateTime() > $now->getPhpDateTime();

if ($variables["node"]->field_end_date->value) {
$endDate = $variables["node"]->field_end_date->date;
$variables['end_time'] = $endDate->format('g:i A T', ['timezone' => date_default_timezone_get()]);
}
break;
}
}

/**
* Implements hook_theme().
*/
function digital_gov_theme(): array {
return [
'author_image' => [
'variables' => [
'author' => NULL,
],
],
];
}

/**
* Preprocessor for author_image theme function.
*/
function digital_gov_preprocess_author_image(array &$vars): void {
$profile_source = $vars["author"]["#entity"]->field_profile_source->value ?? NULL;
$github = $vars["author"]["#entity"]->field_github->value ?? NULL;

$slug = $vars["author"]["#entity"]->field_slug->value;
switch (TRUE) {
case $profile_source === 'github' && $github:
// Author has selected GitHub and specified a GitHub user ID.
$vars['icon_path'] = sprintf('https://github.com/%s.png?size=50', $github);
break;

case $profile_source === 'digit-light':
case $profile_source === 'digit-dark':
case $profile_source === 'digit-pride':
$vars['icon_path'] = sprintf('img/%s.png', $profile_source);
break;

default:
if ($github) {
// Author did not select GitHub but use a GitHUB ID if they have one.
$vars['icon_path'] = sprintf('https://github.com/%s.png?size=50', $github);
}
else {
// No source selected OR they picked GitHub without a GitHub ID
// choose between light and dark based on length of the slug.
$vars['icon_path'] = sprintf(
'img/digit-%s.png',
strlen($slug ?? $vars['author']['#plain_text']) % 2 ? 'dark' : 'light'
);
}
break;
}
}

/**
Expand Down
19 changes: 19 additions & 0 deletions web/themes/custom/digital_gov/templates/author-image.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{#
# Displays profile image for an author
EXPECTED VARIABLES:
- author: render array of author node
An author can define where they want to pull their author photo from:
- github
- digit-dark
- digit-light
- digit-pride
icon_path is set in digital_gov_preprocess_author_image()
#}

<img
class="author__photo-img usa-media-block__img"
src="/{{ active_theme_path() }}/{{ icon_path }}"
alt=""
/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{#
/**
* @file
* Default theme implementation for a field.
*
* To override output, copy the "field.html.twig" from the templates directory
* to your theme's directory and customize it, just like customizing other
* Drupal templates such as page.html.twig or node.html.twig.
*
* Instead of overriding the theming for all fields, you can also just override
* theming for a subset of fields using
* @link themeable Theme hook suggestions. @endlink For example,
* here are some theme hook suggestions that can be used for a field_foo field
* on an article node type:
* - field--node--field-foo--article.html.twig
* - field--node--field-foo.html.twig
* - field--node--article.html.twig
* - field--field-foo.html.twig
* - field--text-with-summary.html.twig
* - field.html.twig
*
* Available variables:
* - attributes: HTML attributes for the containing element.
* - label_hidden: Whether to show the field label or not.
* - title_attributes: HTML attributes for the title.
* - label: The label for the field.
* - multiple: TRUE if a field can contain multiple items.
* - items: List of all the field items. Each item contains:
* - attributes: List of HTML attributes for each item.
* - content: The field item's content.
* - entity_type: The entity type to which the field belongs.
* - field_name: The name of the field.
* - field_type: The type of the field.
* - label_display: The display settings for the label.
*
* @see template_preprocess_field()
*
* @ingroup themeable
*/
#}

<article class="list-topics">
<h3 class="dg-promos__heading">Related Topics</h3>
{% for item in items %}
{% set topic = item.content['#entity'] %}
<a href="{{ item.content['#url'] }}" data-topic="{{ topic.field_slug.value }}"
>{{ item.content['#title'] }}</a>
{% endfor %}
</article>
Loading

0 comments on commit 93ab993

Please sign in to comment.