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

Usagov 1685 fix site banner #1769

Draft
wants to merge 25 commits into
base: dev
Choose a base branch
from
Draft

Conversation

YaritzaGarcia
Copy link
Contributor

@YaritzaGarcia YaritzaGarcia commented Jul 26, 2024

Jira Task

https://cm-jira.usa.gov/browse/USAGOV-1685

Description

I added a variable to Drupal's state to check if the banner is already placed or not. If that variable is FALSE and the banner is supposed to be visible, it runs the "drupal_flush_all_caches();" function.

I changed all the code for how we place a site banner but the interface and the process in which a content admin adds it remains the same. These were the things I did:

  • Update the readme
  • Remove the old code from usa_twig_vars.module
  • Create a new module for the site_banner called usa_site_banner
  • Remove the twig template that I was using to place the block

Type of Changes

  • New Feature
  • Bugfix
  • Frontend (Twig, Sass, JS)
    • Add screenshot showing what it should look like
  • Drupal Config (requires "drush cim")
  • New Modules (requires rebuild)
  • Documentation
  • Infrastructure
    • CMS
    • WAF
    • Egress
    • Tools
  • Other

Testing Instructions

  1. Run bin/init and bin/drush cim
  2. Create a Content Administrator account and log in using that account
  3. Go to the Content blocks page localhost/admin/content/block
  4. Click + Add content block.
  5. Fill in the required fields for the Site Banner.
    • Make sure you select the correct language for the banner.
  6. Find the checkbox labeled Place above header.
    • Check this box if you want the banner to appear in the header_top region.
    • Uncheck this box if you want to remove the banner from the header_top region.
  7. Click Save to create or update the Site Banner block.
  8. Visit the site to ensure the banner appears or is removed from the region.
  9. Log out from the account and check that the banner is visible for anonymous users.
  10. Unplaced the block and check it was removed from anonymous users as well.
  11. Repeat these steps for both languages and also add multiple site_banners
  12. Keep the banners placed and go to Docker Desktop and find the cms container
  13. Click the 3 dots in the Actions column and click "Open in terminal"
  14. In the terminal, type ./scripts/tome-run.sh and wait for tome to run
  15. Once tome is done, go to http://127.0.0.1 and check that the banners that you placed are visible in all the pages.

Change Requirements

  • Requires New Documentation (Link: {docs/SiteBanner.md})
  • Requires New Config
  • Requires New Content

Validation Steps

Security Review

  • Adds/updates software (including a library or Drupal module)
  • Communication with external service
  • Changes permissions or workflow
  • Requires SSPP updates

Reviewer Reminders

  • Reviewed code changes
  • Reviewed functionality
  • Security review complete or not required

Post PR Approval Instructions

Follow these steps as soon as you merge the new changes.

  1. Go to the USAGov Circle CI project.
  2. Find the commit of this pull request.
  3. Build and deploy the changes.
  4. Update the Jira ticket by changing the ticket status to Review in Test and add a comment. State whether the change is already visible on cms-dev.usa.gov and beta-dev.usa.gov, or if the deployment is still in process.

@YaritzaGarcia YaritzaGarcia marked this pull request as ready for review July 30, 2024 18:49
Copy link
Member

@akf akf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have some disappointing news: I see a problem. I'm testing this a little differently than you described, but I think the principle is the same:

  • I'm editing the blocks in a "normal" browser window
  • I opened an incognito window to view the site as the "anonymous" user
  • Each time I change a block and save in the first window, I go back to my "incognito" window and refresh the page to see what Ms. Anonymous sees.

At first I was really confused because it seemed as if it was working sometimes and not others, and I could tell the cache was getting refreshed during the "working" page loads because they'd be really slow. Well, it turns out that was probably because I was clicking around and looking at other pages.

I turned on my debugger to see when this code gets executed, and if the CMS user saves the block and then loads a page to look at the header, your new code is executed then ... because a logged-in user gets the full page re-built.

But if the CMS user just saves the page and doesn't leave the admin area, and the anonymous user views the page, we don't hit preprocess_region for this header block (assuming that an anonymous user has looked at it before, of course).

Have you tried to get some code like this to run when the block change is saved in the first place? (I would assume yes, and that it wasn't so easy.)

@YaritzaGarcia
Copy link
Contributor Author

Thanks for reviewing! I'm going to take a look at this and see what's going on.

@YaritzaGarcia
Copy link
Contributor Author

@akf Good news! I think I found a new way to add the site banner (I found it last week but I've been doing some testing)

Copy link
Member

@akf akf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is working beautifully, but again I have frustrating news. :-(

After testing this out as you describe, I decided to look at the Configuration Sync report at http://localhost/admin/config/development/configuration (log in as a Site Admin for that) and I saw that 2 blocks, named block.block.site_banner_32 and block.block.site_banner_34, would be deleted on next import. (I deleted one myself; it must have been number 33.)

So, in other words, they would be deleted the next time we deploy code!

So while this is cleaner in a lot of ways, your initial implementation, where someone needed to clear the cache or maybe just visit some pages while logged in to get the banner to show up, was preferable.

I still think there should be a way to get this to work properly, possibly combining ideas from the two approaches. The underlying issue here is that any changes made in the CMS, need to be saved as content in the database (not as exportable configuration). I forgot that blocks fall into the "exportable configuration" category!

I hate to bring nothing but disappointment, so I looked around a bit and I found this: https://www.reddit.com/r/drupal/comments/ut42uf/comment/i97egf6/

They're suggesting using config_ignore, which is a project that still appears to be going strong.

I would say check in with @mdranove but he's just started vacation (perhaps when he gets back?) because he has experience with config_split. It looks like they are entirely compatible: https://sitestudiodocs.acquia.com/8.0/user-guide/setup-config-ignore-and-config-split

- The `usa_site_banner_entity_insert` is a hook that runs when a Content Admin creates a site_banner. This hook creates a block by calling the `usa_site_banner_create_block` function and then places it in the `header_top` region if necessary by calling the `usa_site_banner_place_block` function.
- The `usa_site_banner_entity_update` is a hook that runs when a Content Admin updates a site_banner. This hook creates a block if necessary by calling the `usa_site_banner_create_block` function and then places it in the `header_top` region if necessary by calling the `usa_site_banner_place_block` function.
- The `usa_site_banner_place_block` is a fuction that places a Block in a region by setting the `status` value of the Block. Since in order to change the value you need to have a Block created, this function calls the `usa_site_banner_create_block` function in case there is no Block for the site_banner.
- The `usa_site_banner_create_block` is a function that creates a Block for a site_banner based on the BlockContent data.
- `web/themes/custom/usagov/templates/field--block-content--field-place-above-header.html.twig`
- For some reason the checkbox added text below the site banner so I added this empty file to prevent this text from appearing.
Copy link
Member

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.

Copy link
Contributor

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?

Copy link
Member

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).

Copy link
Contributor Author

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.

@akf
Copy link
Member

akf commented Sep 27, 2024

Hi @YaritzaGarcia! We're all super-busy and since this is not a show-stopper, I'm changing the PR to a "draft" (so someone doesn't merge it by accident) for now.

@akf akf marked this pull request as draft September 27, 2024 01:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants