Add create/edit translation button to editor metabox#616
Add create/edit translation button to editor metabox#616apermo wants to merge 5 commits intolloc:masterfrom
Conversation
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.
There was a problem hiding this comment.
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.
| 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(); |
There was a problem hiding this comment.
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();
Closes #606
Summary
dashicons-plus— Quick Create button (when enabled) or classicpost-new.phplink withmsls_id/msls_langparams opening in a new tabdashicons-external— link to the translation's edit page in a new tabdashicons-external(notdashicons-editlike in the listing)forattribute on metabox labels (CSS classes moved toclassattribute)Test plan
post-new.php?msls_id=...&msls_lang=...composer test— 408 tests pass