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 8, 2024
1 parent 0df1971 commit 9259b8d
Show file tree
Hide file tree
Showing 29 changed files with 1,708 additions and 19 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"composer/installers": "^2.0",
"cweagans/composer-patches": "^1.7",
"drupal/admin_toolbar": "^3.4",
"drupal/components": "^3.1",
"drupal/content_moderation_notifications": "^3.6",
"drupal/core-composer-scaffold": "^10.2",
"drupal/core-project-message": "^10.2",
Expand Down
5 changes: 5 additions & 0 deletions composer.log
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@ ae2759e9c45acbf0d8378d04e842d0a8|Matt Poole|develop|Tue Jul 2 13:45:43 EDT 2024
19cf61801de888c57552ec84d66ac668|christian medders|feature/dg-28-shortcode-embed|Wed Oct 16 15:12:23 EDT 2024|./composer.sh require drupal/embedded_content:^2.0
5cef6cc07d3331402a059556429ad233|christian medders|feature/dg-28-shortcode-embed|Wed Oct 16 15:53:48 EDT 2024|./composer.sh remove drupal/ckeditor5_embedded_content
ea93266b87251a27fec5df04a3cbd5d0|Matt Poole|feature/DIGITAL-28-shortcode-embed|Thu Oct 24 16:50:38 EDT 2024|./composer.sh require drupal/multivalue_form_element:@beta
90c5ee5cfbe63ac6954ed970139ed378|Matt Poole|feature/DIGITAL-45-roles-and-perms|Tue Nov 5 10:26:54 EST 2024|./composer.sh require drupal/remove_username:^1.5
5221f503d2bf9ec96f0acb4d425c1afa|Matt Poole|feature/DIGITAL-45-roles-and-perms|Tue Nov 5 12:50:14 EST 2024|./composer.sh require drupal/override_node_options
2c4015cb5bdeefb05c1994e70b9762f1|Matt Poole|feature/DIGITAL-45-roles-and-perms|Wed Nov 6 09:44:05 EST 2024|./composer.sh require drupal/disable_user_1_edit:^1.6
19e48982b7d8f46673a705bf49e7b861|Matt Poole|feature/DIGITAL-45-roles-and-perms|Wed Nov 6 09:56:09 EST 2024|./composer.sh require drupal/vbo_workflow_transition:1.0.x-dev@dev
3d742a578663c259c7f20fe529971425|Matt Poole|feature/DIGITAL-45-roles-and-perms|Wed Nov 6 09:56:58 EST 2024|./composer.sh require drupal/views_bulk_operations
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 @@ -245,7 +253,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 @@ -161,7 +169,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 @@ -178,7 +186,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 9259b8d

Please sign in to comment.