-
Notifications
You must be signed in to change notification settings - Fork 10
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
Usagov 1685 fix site banner #1769
Draft
YaritzaGarcia
wants to merge
25
commits into
dev
Choose a base branch
from
USAGOV-1685-Fix-Site-banner
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
36ac5be
USAGOV-1685-Fix-Site-banner: Testing cache
YaritzaGarcia 1491687
USAGOV-1685-Fix-Site-banner: Merge branch 'dev' into USAGOV-1685-Fix-…
YaritzaGarcia 8c1ae10
USAGOV-1685-Fix-Site-banner: Issue fixed. Added new if statement that…
YaritzaGarcia 07c9f75
Merge branch 'dev' into USAGOV-1685-Fix-Site-banner
YaritzaGarcia 87b4367
USAGOV-1685-Fix-Site-banner: Fix lint errors and remove comment
YaritzaGarcia f4c3338
Merge branch 'dev' into USAGOV-1685-Fix-Site-banner
akf 37416cf
Merge branch 'dev' into USAGOV-1685-Fix-Site-banner
YaritzaGarcia 0437155
USAGOV-1685-Fix-Site-banner: Moving the logic to another hook, still …
YaritzaGarcia 2a3dc1c
USAGOV-1685-Fix-Site-banner: old testing stuff
YaritzaGarcia 42eb5a5
USAGOV-1685-Fix-Site-banner: Merge branch 'dev' into USAGOV-1685-Fix-…
YaritzaGarcia e3ff3f9
USAGOV-1685-Fix-Site-banner: Merge branch 'dev' into USAGOV-1685-Fix-…
YaritzaGarcia 23f906a
USAGOV-1685-Fix-Site-banner: Merge branch 'dev' into USAGOV-1685-Fix-…
YaritzaGarcia ba57bd8
USAGOV-1685-Fix-Site-banner: testing
YaritzaGarcia 9ccff1f
Merge branch 'dev' into USAGOV-1685-Fix-Site-banner
YaritzaGarcia 69e63f1
USAGOV-1685-Fix-Site-banner: Working. Placing the block by creating i…
YaritzaGarcia dd38546
USAGOV-1685-Fix-Site-banner: Move everything to a separate module and…
YaritzaGarcia b927650
USAGOV-1685-Fix-Site-banner: Fix lint errors
YaritzaGarcia 7bbd9c0
USAGOV-1685-Fix-Site-banner: FIX LINT ERRORS
YaritzaGarcia 701abce
USAGOV-1685-Fix-Site-banner: Merge branch 'dev' into USAGOV-1685-Fix-…
YaritzaGarcia c1a5eed
USAGOV-1685-Fix-Site-banner: Install new site banner module
YaritzaGarcia f839cdf
USAGOV-1685-Fix-Site-banner: Fix condition in functions
YaritzaGarcia c713225
USAGOV-1685-Fix-Site-banner: Update readme
YaritzaGarcia 91d875e
Merge branch 'dev' into USAGOV-1685-Fix-Site-banner
YaritzaGarcia 2d3986c
USAGOV-1685-Fix-Site-banner: Fix error in readme
YaritzaGarcia 066d1b0
Merge branch 'dev' into USAGOV-1685-Fix-Site-banner
akf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
name: 'USAGov Site Banner Module' | ||
type: module | ||
description: 'Place the site banner in the site' | ||
core_version_requirement: ^10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?php | ||
|
||
use Drupal\block\Entity\Block; | ||
use Drupal\block_content\Entity\BlockContent; | ||
|
||
/** | ||
* Implements hook_entity_insert() | ||
* When a Content Admin creates a site_banner, this function creates a block | ||
* and places it in the header_top region if necessary. | ||
*/ | ||
function usa_site_banner_entity_insert($entity) { | ||
if ($entity->getEntityTypeId() == 'block_content' && $entity->bundle() == "site_banner") { | ||
usa_site_banner_place_block($entity); | ||
} | ||
} | ||
|
||
/** | ||
* Implements hook_entity_update() | ||
* When a Content Admin updates a site_banner, this function creates a block, if necessary, | ||
* and places it in the header_top region, if necessary. | ||
*/ | ||
function usa_site_banner_entity_update($entity) { | ||
if ($entity->getEntityTypeId() == 'block_content' && $entity->bundle() == "site_banner") { | ||
usa_site_banner_place_block($entity); | ||
} | ||
} | ||
|
||
/** | ||
* Places a Block in a region using the BlockContent data to create the Block. | ||
* @param BlockContent $block_content The BlockContent you want to place in the region. | ||
*/ | ||
function usa_site_banner_place_block(BlockContent $block_content) { | ||
// Get the block if any | ||
$block = Block::load('site_banner_' . $block_content->id()); | ||
// Get the value of the checkbox in the site_banner form | ||
$place_above_header = $block_content->field_place_above_header->value; | ||
|
||
// If the block has not been created, it is created so that the block can be placed in the region. | ||
if (!$block) { | ||
$block = usa_site_banner_create_block($block_content); | ||
} | ||
|
||
// Place the block in the "header_top" region if the checkbox is checked. | ||
if ($place_above_header) { | ||
$block->set('status', 1); | ||
$block->save(); | ||
} | ||
// Removes the block from the "header_top" region if the checkbox is unchecked. | ||
else { | ||
$block->set('status', 0); | ||
$block->save(); | ||
} | ||
} | ||
|
||
/** | ||
* Creates a Block based on the BlockContent data. | ||
* @param BlockContent $block_content The BlockContent for which you want to create the block. | ||
* @return Block The new generated Block. | ||
*/ | ||
function usa_site_banner_create_block(BlockContent $block_content) { | ||
|
||
$block_content_langcode = $block_content->langcode->value; | ||
|
||
// Set visibility to appear based on language. | ||
$visibility = [ | ||
"language" => [ | ||
"id" => "language", | ||
"negate" => FALSE, | ||
"context_mapping" => [ | ||
"language" => "@language.current_language_context:language_interface" | ||
], | ||
"langcodes" => [ | ||
$block_content_langcode => $block_content_langcode | ||
] | ||
] | ||
]; | ||
|
||
// Set all the values needed to create a block, including which region it will be placed in. | ||
$values = [ | ||
'id' => 'site_banner_' . $block_content->id(), | ||
'theme' => 'usagov', | ||
'plugin' => 'block_content:' . $block_content->uuid(), | ||
'region' => 'header_top', | ||
'visibility' => $visibility, | ||
'status' => 0, | ||
'weight' => 0, | ||
'settings' => [], | ||
]; | ||
|
||
// Create and return the new block. | ||
return Block::create($values); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 0 additions & 37 deletions
37
web/themes/custom/usagov/templates/region--header-top.html.twig
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I can explain this one! The checkbox is part of the block content, so the block will render it, and it will fall back on the default theme if nothing is supplied. This is a fine way to suppress it; it still shows up in the admin area (where we want to see it!) because the admin area has a different theme.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious what all of this means for the Benefits Redirect Modal. Should I move forward with the implementation that mirrors how the gov banner is currently done on the prod? Or should I change it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just closing the loop for @YaritzaGarcia, Chris and I DM'd about this. He'll move forward with the existing implementation and we'll expect to update both when we have a better approach (probably based on this newer work).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the update and for reviewing! I will take a look.