Skip to content

Unify JS-Modal templates #1774

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 6 commits into from
Jun 11, 2025
Merged

Unify JS-Modal templates #1774

merged 6 commits into from
Jun 11, 2025

Conversation

pfefferle
Copy link
Member

@pfefferle pfefferle commented Jun 6, 2025

Unify the way we define the modal HTML. We currently have two different ways to define the modal HTML, this is ob_start and string concatination.

I asked chatgpt about the best way to do it: "What is the best approach for mixing PHP with HTML templates: using ob_start, printf, or string concatenation?"

Summary

Goal / Context Recommended Approach
Full HTML templates ob_start + mixed HTML/PHP
Small reusable components/fragments printf / sprintf
Tiny inline HTML (1–2 lines) String concatenation
Translation-aware templates printf + localization placeholders

We are working with bigger HTML templates, so I think we should handle them like a templates (https://phptherightway.com/#plain_php_templates). The ob_* solution therefore is the most straight forward solution in terms of readability and extensibility.

Proposed changes:

  • This PR unifies all modal templates to use ob_*.
  • (Order the attributes alphabetically @obenland 😘)

Other information:

  • Have you written new tests for your changes, if applicable?

Testing instructions:

  • There should be no visible change.

Changelog entry

  • Automatically create a changelog entry from the details below.
Changelog Entry Details

Significance

  • Patch
  • Minor
  • Major

Type

  • Added - for new features
  • Changed - for changes in existing functionality
  • Deprecated - for soon-to-be removed features
  • Removed - for now removed features
  • Fixed - for any bug fixes
  • Security - in case of vulnerabilities

Message

@pfefferle pfefferle requested review from obenland and Copilot June 6, 2025 07:21
@pfefferle pfefferle self-assigned this Jun 6, 2025
@pfefferle pfefferle added [Type] Janitorial Skip Changelog Disables the "Changelog Updated" action for PRs where changelog entries are not necessary. labels Jun 6, 2025
Copilot

This comment was marked as outdated.

@github-actions github-actions bot added [Block] Follow Me [Block] Reactions [Block] Remote Reply aka "Reply on the Fediverse", in the comment list [Feature] Reactions [Focus] Editor Changes to the ActivityPub experience in the block editor labels Jun 6, 2025
@pfefferle pfefferle requested a review from Copilot June 9, 2025 14:16
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR standardizes modal HTML generation by using output buffering (ob_start) instead of string concatenation and reorders attributes alphabetically for consistency.

  • Converted inline string templates in reactions and follow-me to ob_start blocks.
  • Alphabetized input/button attributes in remote-reply.
  • Removed old concatenated string assignments for modal content.

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/remote-reply/render.php Reordered input/button attributes alphabetically
src/reactions/render.php Replaced string-concat modal HTML with an ob_start template
src/follow-me/render.php Converted follow-me modal HTML to an ob_start block
build/remote-reply/render.php Mirrored attribute reordering in build output
build/reactions/render.php Mirrored ob_start template conversion in build output
build/follow-me/render.php Mirrored ob_start template conversion in build output
Comments suppressed due to low confidence (3)

src/reactions/render.php:139

  • The newly introduced modal HTML lacks tests; consider adding unit or integration tests to verify the resulting HTML structure and bindings.
<ul class="reactions-list">

src/follow-me/render.php:108

  • [nitpick] Add a comment explaining the purpose of this buffer start and how $modal_content is used by Blocks::render_modal for clarity.
ob_start();

src/follow-me/render.php:144

  • [nitpick] The keydown handler name differs from actions.onInputKeydown used elsewhere; consider standardizing the callback naming for consistency.
data-wp-on--keydown="actions.handleKeyDown"

@obenland obenland merged commit 74583b5 into trunk Jun 11, 2025
11 checks passed
@obenland obenland deleted the update/modal branch June 11, 2025 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Follow Me [Block] Reactions [Block] Remote Reply aka "Reply on the Fediverse", in the comment list [Feature] Reactions [Focus] Editor Changes to the ActivityPub experience in the block editor Skip Changelog Disables the "Changelog Updated" action for PRs where changelog entries are not necessary. [Type] Janitorial
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants