Skip to content

feat(media): Add Copy URL to Media Browser context menu#16893

Open
Ibochkarev wants to merge 2 commits intomodxcms:3.xfrom
Ibochkarev:feat/copy-url-media-browser
Open

feat(media): Add Copy URL to Media Browser context menu#16893
Ibochkarev wants to merge 2 commits intomodxcms:3.xfrom
Ibochkarev:feat/copy-url-media-browser

Conversation

@Ibochkarev
Copy link
Collaborator

What does it do?

Adds a "Copy URL" option to the Media Browser and File Tree context menus. Users can right-click a file and copy its absolute URL to the clipboard. The feature uses urlExternal or urlAbsolute when available, falling back to fullRelativeUrl or url.

Backend changes:

  • modMediaSource and modS3MediaSource: add urlExternal and urlAbsolute to file list data, pass $file_list to getListFileContextMenu
  • getListFileContextMenu: add Copy URL menu item when file has a viewable URL; show for public files next to Copy Path, for private files as a separate item

Frontend changes:

  • Extract copyToClipboard to MODx.util.copyToClipboard in utilities.js (removes duplication)
  • Use Clipboard API with execCommand fallback for older/non-HTTPS contexts
  • Add copyUrl handler in modx.browser.js and modx.tree.directory.js

Why is it needed?

Users need to quickly copy file URLs for sharing or embedding. Previously only Copy Path (relative path) was available.

How to test

  1. Open Media Browser or File Tree in the manager
  2. Right-click a file (image, document, etc.)
  3. Select "Copy URL" from the context menu
  4. Paste elsewhere — the absolute URL should be in the clipboard

Related issue(s)/PR(s)

Resolves #13618

- Add urlExternal and urlAbsolute to file list for Media Browser
- Add Copy URL menu item for files with viewable URL
- Extract copyToClipboard to MODx.util for reuse
- Use Clipboard API with execCommand fallback
- Fix phpcs line length in modified methods

Resolves modxcms#13618
@Ibochkarev Ibochkarev marked this pull request as ready for review February 25, 2026 02:46
@biz87
Copy link

biz87 commented Feb 25, 2026

Code Review

Summary

Adds a "Copy URL" option to the Media Browser and File Tree context menus. Backend changes add urlExternal and urlAbsolute fields to file list data in both modMediaSource and modS3MediaSource, and pass the file data to getListFileContextMenu() for URL-aware menu construction. Frontend extracts a shared MODx.util.copyToClipboard() utility (with Clipboard API + execCommand fallback), replaces duplicated clipboard code in both modx.browser.js and modx.tree.directory.js, and adds copyUrl handlers.

Suggestions

  • modx.browser.js:228 / modx.tree.directory.js:712: The copyUrl method builds the URL fallback chain (urlExternal || urlAbsolute || fullRelativeUrl || url). The tree version omits fullRelativeUrl from the chain — consider aligning both handlers for consistency.

Assessment

Well-structured multi-file change. The copyToClipboard extraction eliminates code duplication properly. Guard clauses (if (!node) return) are added to existing copyRelativePath handlers as a good defensive improvement. The context menu logic correctly distinguishes between public files (where Copy URL sits alongside Copy Path and Open) and non-public files (separate Copy URL item). Both modMediaSource and modS3MediaSource are updated consistently. The $file_list array is now built before the menu, which is the right approach since the menu needs URL data.

Verdict: Approve

@Ibochkarev Ibochkarev added the feature Request about implementing a brand new function or possibility. label Feb 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature Request about implementing a brand new function or possibility.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Media Browser - add Copy Url

2 participants