Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Digital-233: Creating the homepage content #86

Merged
merged 8 commits into from
Jan 6, 2025
1 change: 1 addition & 0 deletions .homepage-uuid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
df0e2d62-c293-42be-8165-84542c35129d
3 changes: 3 additions & 0 deletions config/sync/field.storage.node.field_landing_page_type.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ settings:
-
value: resources
label: Resources
-
value: homepage
label: Homepage
allowed_values_function: ''
module: options
locked: false
Expand Down
3 changes: 3 additions & 0 deletions orch/deploy_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,7 @@ fi
# Clear cache after installation
drush cr

# Set the homepage. Custom functionality for Digital.gov.
drush set-hp -y

./orch/show_file.sh $0 end
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
_meta:
version: '1.0'
entity_type: node
uuid: df0e2d62-c293-42be-8165-84542c35129d
bundle: landing_page
default_langcode: en
depends:
e60a3199-17d7-4c13-8b76-f0bbaef67bcd: node
f98c359f-6231-42dd-87b4-f6b0012bfbc8: node
default:
revision_uid:
-
target_id: 1
status:
-
value: true
uid:
-
target_id: 1
title:
-
value: 'Better websites. Better government.'
created:
-
value: 1734639806
promote:
-
value: false
sticky:
-
value: false
moderation_state:
-
value: published
path:
-
alias: /better-websites-better-government
langcode: en
pathauto: 1
field_buttons:
-
target_uuid: e60a3199-17d7-4c13-8b76-f0bbaef67bcd
title: 'View Events'
options: { }
-
target_uuid: f98c359f-6231-42dd-87b4-f6b0012bfbc8
title: 'Join Communities'
options: { }
field_landing_page_type:
-
value: homepage
mattsqd marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 6 additions & 0 deletions web/modules/custom/default_content_config/drush.services.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
services:
init.commands:
class: \Drupal\default_content_config\Commands\CustomCommands
arguments: ["@config.factory", "@entity_type.manager"]
tags:
- { name: drush.command }
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

namespace Drupal\default_content_config\Commands;

use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityTypeManager;
use Drush\Commands\DrushCommands;

/**
* Drush command file for Default Content Config.
*/
class CustomCommands extends DrushCommands {

/**
* The config factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;

/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManager
*/
protected $entityTypeManager;

/**
* Custom Commands constructor.
*/
public function __construct(ConfigFactoryInterface $configFactory, EntityTypeManager $entityTypeManager) {
parent::__construct();
$this->configFactory = $configFactory;
$this->entityTypeManager = $entityTypeManager;
}

/**
* A custom Drush command to set the homepage URL post site install.
*
* @command drush-command:set-homepage
*
* @aliases set-hp
*/
public function setHomepage(array $options = []): void {
$no_interaction = FALSE;
if ($options['no-interaction'] || $options['yes']) {
$no_interaction = TRUE;
}
$homepage_uuid_file = '../.homepage-uuid';
$homepage_uuid = file_get_contents($homepage_uuid_file);
if (!$homepage_uuid) {
if ($no_interaction) {
$this->io()->warning(dt('Your homepage has not been set yet, do so by calling drush set-hp'));
return;
}
else {
$homepage_uuid = $this->ask('What is the UUID of your homepage node?');
if (!$homepage_uuid) {
throw new \Exception(dt('A homepage is required'));
}
file_put_contents($homepage_uuid_file, $homepage_uuid);
}
}

$nodes = $this->entityTypeManager->getStorage('node')->loadByProperties(['uuid' => $homepage_uuid]);
if (empty($nodes)) {
file_put_contents($homepage_uuid_file, '');
throw new \Exception(dt('Unable to find a node for homepage by UUID ') . $homepage_uuid);
}
/** @var \Drupal\node\NodeInterface $node */
$node = reset($nodes);
$homepage_url = '/node/' . $node->id();
$this->configFactory->getEditable('system.site')
->set('page.front', $homepage_url)
->save();
$this->io()->success(dt('Homepage has been set to ') . $homepage_url);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
{#
/**
* @file
* Default theme implementation to display a node.
*
* Available variables:
* - node: The node entity with limited access to object properties and methods.
* Only method names starting with "get", "has", or "is" and a few common
* methods such as "id", "label", and "bundle" are available. For example:
* - node.getCreatedTime() will return the node creation timestamp.
* - node.hasField('field_example') returns TRUE if the node bundle includes
* field_example. (This does not indicate the presence of a value in this
* field.)
* - node.isPublished() will return whether the node is published or not.
* Calling other methods, such as node.delete(), will result in an exception.
* See \Drupal\node\Entity\Node for a full list of public properties and
* methods for the node object.
* - label: (optional) The title of the node.
* - content: All node items. Use {{ content }} to print them all,
* or print a subset such as {{ content.field_example }}. Use
* {{ content|without('field_example') }} to temporarily suppress the printing
* of a given child element.
* - author_picture: The node author user entity, rendered using the "compact"
* view mode.
* - metadata: Metadata for this node.
* - date: (optional) Themed creation date field.
* - author_name: (optional) Themed author name field.
* - url: Direct URL of the current node.
* - display_submitted: Whether submission information should be displayed.
* - attributes: HTML attributes for the containing element.
* The attributes.class element may contain one or more of the following
* classes:
* - node: The current template type (also known as a "theming hook").
* - node--type-[type]: The current node type. For example, if the node is an
* "Article" it would result in "node--type-article". Note that the machine
* name will often be in a short form of the human readable label.
* - node--view-mode-[view_mode]: The View Mode of the node; for example, a
* teaser would result in: "node--view-mode-teaser", and
* full: "node--view-mode-full".
* The following are controlled through the node publishing options.
* - node--promoted: Appears on nodes promoted to the front page.
* - node--sticky: Appears on nodes ordered above other non-sticky nodes in
* teaser listings.
* - node--unpublished: Appears on unpublished nodes visible only to site
* admins.
* - title_attributes: Same as attributes, except applied to the main title
* tag that appears in the template.
* - content_attributes: Same as attributes, except applied to the main
* content tag that appears in the template.
* - author_attributes: Same as attributes, except applied to the author of
* the node tag that appears in the template.
* - title_prefix: Additional output populated by modules, intended to be
* displayed in front of the main title tag that appears in the template.
* - title_suffix: Additional output populated by modules, intended to be
* displayed after the main title tag that appears in the template.
* - view_mode: View mode; for example, "teaser" or "full".
* - teaser: Flag for the teaser state. Will be true if view_mode is 'teaser'.
* - page: Flag for the full page state. Will be true if view_mode is 'full'.
*
* @see template_preprocess_node()
*
* @ingroup themeable
*/
#}

<main
role="main" id="main-content">
{# <div class="grid-container-desktop margin-bottom-5"> #}
<section class="usa-section" id="resources_featured">
<div class="tablet-lg:grid-container tablet-lg:grid-container-desktop">
<div class="grid-row tablet-lg:grid-gap-4">
<div class="grid-col-12 tablet-lg:grid-col-4">
<div class="box">
<h1 class="resources-featured__title">
{{ node.title.value }}
</h1>
{% set links = content.field_buttons|field_value %}
{% for link in links %}
<a class="btn btn-home" href="{{ link['#url'] }}" title="{{ link['#title'] }}">
<span>{{ link['#title'] }}</span>
<svg class="usa-icon dg-icon dg-icon--standard margin-bottom-05" aria-hidden="true" focusable="false" role="img">
<use xlink:href="/{{ active_theme_path() }}/static/uswds/img/sprite.svg#arrow_forward"></use>
</svg>
</a>
{% endfor %}
</div>
</div>
<div class="grid-col-12 tablet-lg:grid-col-8">
<div class="resources-content">
[Place holder for resources list]
{# NOT-MIGRATED
{{/* Get all of the resources */}}
{{- $resources := (where .Site.Pages.ByTitle "Section" "resources") -}}
{{- $guides := (where .Site.Pages.ByTitle "Section" "guides") -}}

{{/* Get only the pages that are greater than or equal to 3 */}}
{{- $resourcesfeatured := (where $resources ".Params.weight" "ge" 3 ) -}}
{{- $guidesfeatured := (where $guides ".Params.weight" "ge" 6 ) -}}

{{- $allFeatured := union $resourcesfeatured $guidesfeatured -}}

{{/* Sort all of the resources by weight */}}
{{- $resourcesfeatured := (sort $allFeatured "Weight" "desc" ) -}}

{{- partialCached "core/featured-collection.html" (dict "list" $resourcesfeatured "heading" "How to implement 21st Century IDEA") -}} #}
<footer>
<div class="grid-row tablet-lg:grid-gap-2">
<div class="grid-col-12">
<p class="dg-more-link">
<a href="{{ 'topics/digital-service-delivery/' }}">
<span>Deliver better digital services</span>
<svg class="usa-icon dg-icon dg-icon--standard margin-bottom-05" aria-hidden="true" focusable="false">
<use xlink:href="/{{ active_theme_path() }}/static/uswds/img/sprite.svg#arrow_forward"></use>
</svg>
</a>
</p>
</div>
</div>
</footer>
</div>
</div>
</div>
</div>
</section>

{# Digital.gov Communities of Practice #}
<section class="grid-container-desktop usa-section">
{{ drupal_view('featured_communities', 'default') }}
</section>

[Place holder for news list]

{# NOT-MIGRATED
{{/* News */}}
{{- partialCached "core/home/news_featured.html" . -}} #}

{# </div> #}
</main>
Loading