Skip to content

Add create/edit translation button to editor metabox#616

Closed
apermo wants to merge 5 commits intolloc:masterfrom
apermo:feature/606-metabox-create-new-button-v2
Closed

Add create/edit translation button to editor metabox#616
apermo wants to merge 5 commits intolloc:masterfrom
apermo:feature/606-metabox-create-new-button-v2

Conversation

@apermo
Copy link
Copy Markdown
Contributor

@apermo apermo commented Apr 20, 2026

Closes #606

Summary

  • Add an action button next to each language's select/autocomplete in the editor metabox
  • No translation linked: shows dashicons-plus — Quick Create button (when enabled) or classic post-new.php link with msls_id/msls_lang params opening in a new tab
  • Translation linked: shows dashicons-external — link to the translation's edit page in a new tab
  • Only appears when the current post has been saved (not auto-draft)
  • In autocomplete mode, toggles dynamically between create and edit states
  • Quick Create success in the metabox uses dashicons-external (not dashicons-edit like in the listing)
  • Fixes for attribute on metabox labels (CSS classes moved to class attribute)
  • Moves Quick Create button CSS into the LESS source

Test plan

  • Open a saved post with no translations — verify "+" appears per language
  • Quick Create enabled: click "+" — draft created, icon changes to external arrow
  • Quick Create disabled: click "+" — new tab opens post-new.php?msls_id=...&msls_lang=...
  • Post with existing translations — external arrow icon per linked language
  • Autocomplete mode: select a post — "+" hides, arrow shows; clear field — reverses
  • Auto-draft post — no action buttons appear
  • composer test — 408 tests pass

apermo added 5 commits April 20, 2026 17:45
Update render_select and render_input tests to expect
the new create/edit action element and the additional
WordPress function mocks.
Add an action button next to each language row in the
editor metabox. Shows dashicons-plus when no translation
is linked (Quick Create button or classic post-new.php
link) and dashicons-external when linked (edit link
opening in a new tab). Only visible for saved posts.

Closes lloc#606
Hide create button and show edit link when a post is
selected via autocomplete. Reverse when the field
is cleared.
After Quick Create succeeds in the metabox, use
dashicons-external instead of dashicons-edit and
open the link in a new tab.
Add styles for create-new and edit-link buttons in
the metabox. Move Quick Create button reset and
loading animation into the LESS source.
@apermo apermo requested a review from lloc as a code owner April 20, 2026 15:46
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request enhances the translation metabox by adding direct links to create or edit translations. Key changes include the introduction of the get_create_new_link method in MslsMetaBox.php, new CSS styles for action links, and JavaScript updates to dynamically manage link visibility and icons. Unit tests were also updated to match the revised HTML structure. Feedback was provided to refactor the get_create_new_link method by using the MslsAdminIcon::create() factory method and removing redundant object instantiations to improve code maintainability and consistency.

Comment thread includes/MslsMetaBox.php
Comment on lines +426 to +442
if ( msls_options()->activate_quick_create ) {
$action_icon = ( new MslsAdminIcon( $type ) )
->set_language( $language )
->set_icon_type( 'action' )
->set_id( $post_id )
->set_origin_language( $origin_language );

return $action_icon->get_a();
}

$action_icon = ( new MslsAdminIcon( $type ) )
->set_language( $language )
->set_icon_type( 'action' )
->set_id( $post_id )
->set_origin_language( $origin_language );

$href = $action_icon->get_edit_new();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The instantiation of MslsAdminIcon is duplicated and uses the constructor directly instead of the preferred factory method. Refactoring this to use MslsAdminIcon::create() once will improve maintainability and ensure consistency with how icons are handled elsewhere in the plugin.

		$action_icon = MslsAdminIcon::create( $type )
			->set_language( $language )
			->set_icon_type( 'action' )
			->set_id( $post_id )
			->set_origin_language( $origin_language );

		if ( msls_options()->activate_quick_create ) {
			return $action_icon->get_a();
		}

		$href = $action_icon->get_edit_new();

@apermo apermo closed this Apr 20, 2026
@apermo apermo deleted the feature/606-metabox-create-new-button-v2 branch April 20, 2026 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add 'create new translation' button to editor metabox

1 participant