-
Notifications
You must be signed in to change notification settings - Fork 8
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
Weather Story WFO Publish Confirmation #1392
Conversation
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.
This is quite good. I know it's not what you originally set out to do, but this is nice. One comment that I think needs fixed, but once that's done, I think this is ready to ship and celebrate.
// First, archive any Weather Story nodes that are already | ||
// published if they have the same WFO as was submitted | ||
$wfo_id = $formState->getValue("field_wfo")[0]["target_id"]; | ||
weathergov_unpublish_published_weather_stories($wfo_id); |
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.
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.
Whoa, oof. Good catch
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.
Should be fixed now in 7cd1aba thanks
// The data attribute will reference the id | ||
// of a target button to programmatically click | ||
// on the page's actual form. | ||
// If there is no target, the modal will simply close | ||
const targetButton = document.getElementById( |
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.
This is clever.
As pointed out by Greg, publishing any other type of content node was unpublishing all Weather Story nodes because we were not checking the node type during the publish hook. This commit adds a check.
9b8a534
to
690e6ba
Compare
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.
Looks good
What does this PR do? 🛠️
After eons, this PR addresses #1269. The gist is that when creating a new Weather Story and entering a linked WFO, authors should see a dialog of some sort informing them that there is another Weather Story already published with the same WFO. The dialog will have options to save a draft, cancel, or "replace" -- meaning unpublish the other Weather Story first, then publish the new one.
What does the reviewer need to know? 🤔
Hey, isn't there a way to already do this?
No.
I spent a significant amount of time trying to get this "confirmation, with original form data" concept to work via various Drupal APIs and patterns. None of them worked.
After days of poking at it, I threw my hands up and decided to go with Javascript and some basic hook/template alterations.
Ok, sure, but how does it work?
We add a custom JS file as a theme library called
weather-story-modal-dialog
which handles the logic of an otherwise inert<dialog>
element that is now present in the template for adding weather stories.In the admin theme file, we add a few helper methods and hooks that will load this library.
Additionally, if the form is a Weather Story create form, the hook will query the system for all weather stories that are currently published, passing information about all of them -- including and especially information about their linked WFO Terms -- to the template file as a JSON object tucked away in a script tag.
If the user decides to publish anyway, all existing published Weather Stories with the same WFO will be archived. This happens by default in the publish action now, and is not unique to the dialog.
Boring! How can I just try it out?
Here are some steps to follow to try it out locally:
zap
your containersScreenshots (if appropriate): 📸
Visual summary of "replacing" with a new weather story for Nashville