Repository navigation
Flexible Content: group layouts by category in the Add Layout menu - #573
faisalahammad wants to merge 2 commits into
Conversation
- Add an optional "Category" setting to each layout in the field group editor. - Group the "Add Layout" menu by category, with a small heading per group. - Layouts without a category stay at the top, so existing menus look the same. - Categories follow the order of their first layout, layouts keep their order. - Translate the category like the layout label. - Add PHPUnit tests, schema description and docs. Long layout lists were hard to scan because the menu was one flat list. Fixes WordPress#570
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @Faton1995. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Thanks for the contribution and the effort here! 🙏 A heads-up on how this repo works: a large part of SCF's codebase (field types, Flexible Content, Blocks v3, local fields, forms, value formatting, and most of includes/ and assets/src/js/) is regularly synced from an upstream codebase. Any change we make there, whether a bug fix or a new feature, gets overwritten or causes hard merge conflicts on the next sync. That includes features behind a beta flag. Fixes for those areas arrive through the sync itself, so we can't accept PRs that touch that code, even good ones. |
With many Flexible Content layouts, the "Add Layout" menu is one long flat list and related layouts are hard to find. This adds an optional "Category" setting per layout and groups the menu by it.
What changed
class-acf-field-flexible-content.phpcategorylayout setting (default'') inget_valid_layout(), so older layouts get the key too.translate_field()translates the category like the label.FlexibleContent/Render.phpadd_layout_menu()groups layouts by category. Layouts without a category stay at the top, so existing menus look exactly the same.<li class="acf-fc-popup-category">heading, escaped withesc_html(). No JS change was needed: the popup JS only targets[data-layout], so min/max badges, disabled state and clicks skip the heading.The optional search input from the issue is not part of this PR, it can be a follow-up.
How to test
categoryis kept.PHPUnit tests added for the default value, the flat menu, grouping order and escaping. Full PHP suite and Jest suite pass.
Closes #570
Use of AI Tools
Claude Code was used to help write the change and tests. I reviewed and tested the changes before submitting.