-
Notifications
You must be signed in to change notification settings - Fork 1
Let editor select a featured librarian from the block editor #224
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
base: block-remix
Are you sure you want to change the base?
Changes from all commits
de0a102
a9aded2
c2f8d50
9184c27
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,45 @@ | |
| * @var string $content Block default content. | ||
| * @var WP_Block $block Block instance. | ||
| */ | ||
|
|
||
| // Look up the librarian chosen in the block editor's "Featured Librarian" panel. | ||
| $featured_expert = null; | ||
| $featured_expert_id = absint( $attributes['featuredExpertId'] ?? 0 ); | ||
| if ( $featured_expert_id ) { | ||
| $maybe_expert = get_post( $featured_expert_id ); | ||
| if ( $maybe_expert && 'experts' === $maybe_expert->post_type && 'publish' === $maybe_expert->post_status ) { | ||
| $featured_expert = $maybe_expert; | ||
| } | ||
| } | ||
|
|
||
| // Fallback used when no librarian has been selected in the block editor. | ||
| $default_expert = array( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. probably a requested change? I think it will be cleaner and more supportable if we handle all the variable assignments up here, prior to the start of markup beginning on line 28. There are three operations happening within the markup that I fear are going to make supporting this harder over time:
(The block to compile the events down on lines 131-217 is another concern, but I'm setting that aside since it's already merged) I think I'd propose that we handle all the variable assignment in one chunk, and leave the markup portions of this template to only call the escaping functions. This said, if you feel strongly that we need to merge this and just be done with it, I'm open to pushback here - this seems to work. (As an aside - In my suggested code below, I'm also dropping the use of the |
||
| 'name' => 'Alejandro Paz', | ||
| 'first_name' => 'Alejandro', | ||
| 'url' => 'https://libguides.mit.edu/profiles/apaz', | ||
| 'image' => 'https://libapps.s3.amazonaws.com/accounts/349/images/apaz-100x100.jpg', | ||
| 'excerpt' => 'Librarian for Energy and Environment', | ||
| ); | ||
|
|
||
| // If we have a valid expert, use those values. If not, use the fallback values. | ||
| if ( $featured_expert ) { | ||
| $expert_name = get_the_title( $featured_expert ); | ||
| $expert_first_name = strtok( $expert_name, ' ' ); | ||
| $expert_url = get_post_meta( $featured_expert->ID, 'expert_url', true ); | ||
| $expert_image = get_the_post_thumbnail_url( $featured_expert, 'thumbnail' ); | ||
| $expert_excerpt = get_the_excerpt( $featured_expert ); | ||
| } else { | ||
| $expert_name = $default_expert['name']; | ||
| $expert_first_name = $default_expert['first_name']; | ||
| $expert_url = $default_expert['url']; | ||
| $expert_image = $default_expert['image']; | ||
| $expert_excerpt = $default_expert['excerpt']; | ||
| } | ||
|
|
||
| // Generate the strings for alt text and help link text | ||
| $expert_alt_text = "Headshot of " . $expert_name; | ||
| $expert_help_link_text = "How can " . $expert_first_name . " help you?"; | ||
|
|
||
| ?><section id="featured-and-events"> | ||
| <div class="content-wrapper"> | ||
| <div class="featured-content"> | ||
|
|
@@ -23,15 +62,19 @@ | |
| </article> | ||
| <article class="featured-item side-by-side"> | ||
| <span class="item-type spotlight">Spotlight</span> | ||
| <img src="https://libapps.s3.amazonaws.com/accounts/349/images/apaz-100x100.jpg" alt="Headshot of Alejandro Paz" /> | ||
| <?php if ( $expert_image ) : ?> | ||
| <img src="<?php echo esc_url( $expert_image ); ?>" alt="<?php echo esc_attr( $expert_alt_text ); ?>" /> | ||
| <?php endif; ?> | ||
| <div class="featured-item-content"> | ||
| <hgroup> | ||
| <h3><a href="https://libguides.mit.edu/profiles/apaz">Alejandro Paz</a></h3> | ||
| <h3><a href="<?php echo esc_url( $expert_url ); ?>"><?php echo esc_html( $expert_name ); ?></a></h3> | ||
| <div> | ||
| <p>Librarian for Energy and Environment</p> | ||
| <p><?php echo esc_html( $expert_excerpt ); ?></p> | ||
| </div> | ||
| </hgroup> | ||
| <a class="arrow-right" href="https://libguides.mit.edu/profiles/apaz">How can Alejandro help you?</a> | ||
| <a class="arrow-right" href="<?php echo esc_url( $expert_url ); ?>"> | ||
| <?php echo esc_html( $expert_help_link_text ); ?> | ||
| </a> | ||
| </div> | ||
| </article> | ||
| <article class="featured-item side-by-side"> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| <?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-i18n'), 'version' => 'adae8abbc4a7ca67c4b9'); | ||
| <?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-i18n'), 'version' => '08aea560c65be378d62e'); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
Asked VS Code's copilot about this feedback:
Why per_page: -1 won't fail here: @wordpress/api-fetch ships a fetchAllMiddleware that's part of apiFetch's default middleware stack (used by @wordpress/core-data). When it sees per_page: -1 in the query, it never actually sends -1 to the REST endpoint — it strips it, requests page 1 with a large bounded per_page, then keeps requesting subsequent pages and concatenating results until it runs out, based on the X-WP-Total/X-WP-TotalPages headers. This is the same mechanism core Gutenberg blocks rely on (e.g. the Categories block, Page List block, Query Loop's post-type dropdowns) to fetch "all" entities regardless of count. So the dropdown won't come back empty because of this — it works by design.
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.
Leaving this alone for the time being. I don't expect this field to ever have more than 99 experts, but if this is common convention I'd rather go down that route.