forked from jspellman814/wordpress-composer-managed
-
Notifications
You must be signed in to change notification settings - Fork 1
Fix map template on parent theme #91
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
Merged
Merged
Conversation
This file contains hidden or 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
** Why are these changes being introduced: * Attempting to load the map generates a few warning and error messages in the console. One of them reads: PHP Warning: Undefined array key "v" in /app/web/app/themes/mitlib-parent/templates/page-map-locations.php on line 16 ** Relevant ticket(s): * https://mitlibraries.atlassian.net/browse/lm-306 ** How does this address that need: This improves the way that the map template requests the "v" query parameter. * First, it declares that this is an expected parameter via a call to $wp->add_query_var as part of an init hook. * With that done, we can now get the parameter from the get_query_var function, rather than directly from the $_GET superglobal. * Along the way we also ditch a confusing line of code with an unneeded ternary. ** Document any side effects to this change: * Frankly, I'm not sure that this whole construct is used anywhere. The map looks no different if you append ?v=map to the URL or don't, which is the only value that causes the showMap javascript variable to be a 1. But, I'm leery right now of removing things that end up being needed somehow.
** Why are these changes being introduced: * Attempting to load the map template right now generates the following error message in the logs: PHP Fatal error: Uncaught ValueError: array_rand(): Argument #1 ($array) cannot be empty in /app/web/app/themes/mitlib-parent/templates/page-map-locations.php:63 ** Relevant ticket(s): * https://mitlibraries.atlassian.net/browse/lm-306 ** How does this address that need: * The problem appears to be that the page template doesn't anticipate a condition in which no images are associated with a location record? Which is odd, as there _are_ records in the legacy system which do not have images. Regardless, the Courtyard Cafe record is definitely breaking the map template because the $arMain array in this template ends up being empty. * This changes how this array is handled, only grabbing a random item from $arMain if there is at least one element in the array. Otherwise the default value of '' (now assigned at the start of these lines) is left unchanged. ** Document any side effects to this change: * This template is a pit of vipers, lying in wait for an unsuspecting developer. I barely escaped with my life.
This was a global variable set in functions.php, which is no longer considered a good practice - so I'm changing to define the value on any page template that needs it. See this page for details: https://codex.wordpress.org/Global_Variables There are likely even better ways to handle this, but nothing is a quick, easily achievable approach that puts control over this in the hands of UX.
** Why are these changes being introduced: * An attempt to calculate the URL for location records is currently a bit messy, spawning messages like this in the logs: PHP Warning: Attempt to read property "ID" on bool in /app/web/app/themes/mitlib-parent/templates/page-map-locations.php on line 85 ** Relevant ticket(s): * https://mitlibraries.atlassian.net/browse/lm-306 ** How does this address that need: * This changes how the $pageLink value is calculated within the page template. That value could come from two different places, and the old code relied on WordPress' forgiving nature a bit too much. The new way first assigns $pageLink to the URL for the Location record itself (which is either native to the Location, or is defined as a separate path via the Page Links To plugin - but either was is returned by get_permalink( $post ) ). * Then, for location records which have been set - via the display_page custom field - to render at a different location, we look up that URL via get_permalink( displayPage->ID ). ** Document any side effects to this change: * This change gets made in three locations on the page template, because the template is a bit repetitive and should ideally be supported by some custom functions.
JPrevost
approved these changes
Apr 24, 2023
| // phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotValidated -- need to properly receive 'v' parameter. | ||
| $showMap = ( $_GET['v'] != '' ) && ( $_GET['v'] == 'map' ) ? 1 : 0; | ||
| // phpcs:enable | ||
| $v = get_query_var( 'v' ); |
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 a fantastic example of how clear multiline conditionals are so much clearer than the single line equivalent.
matt-bernhardt
pushed a commit
that referenced
this pull request
May 10, 2023
remove the lh-hsts plugin requirement this causes a conflict with hsts defined in pantheon.yml. users should just use pantheon.yml. see https://docs.pantheon.io/pantheon-yml#enforce-https--hsts
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Ticket: https://mitlibraries.atlassian.net/browse/LM-306
This makes the map template into something usable. Specific changes here are:
$valvariable is being assigned within the map template, only picking a random value from an array if that array is not empty - this is used to pick a thumbnail to represent a location when multiple images have been uploaded.$gStudy24Urlvariable which used to be defined in functions.php, instead defining the variable on the templates which need it. More details and a reference URL are in that commit message.vparameter is defined and handled by the map template (was throwing a warning)$pageLinkvariable is calculated, preventing a scenario where we were trying to extract object properties from a boolean value. The new logic sets$pageLinkbased on the location record as a default, and then overrides that if the location record has been assigned to display at a given page location. (This construct appears three times on the map page template).Please note CodeClimate is flagging the use of variable names that don't follow snake_case naming conventions. Starting to make those changes now will, I fear, start touching more and more lines in the template, which will end in a general rebuild of the template. I don't think that I have time for that, for as much as it would carry some advantages.
Developer
Secrets
Documentation
Accessibility
our guide and
all issues introduced by these changes have been resolved or opened as new
issues (link to those issues in the Pull Request details above)
Stakeholder approval
Dependencies
NO dependencies are updated
Code Reviewer
(not just this pull request message)