@@ -407,9 +407,34 @@ const LinkField = ({
407407 publishButton . classList . add ( className ) ;
408408 }
409409 } ) ;
410- const dataTextAlternate = publishButton . getAttribute ( 'data-text-alternate' ) ;
410+ const buttonTitle = publishButton . querySelector ( '.btn__title' ) ;
411+ const dataTextAlternate = publishButton . dataset . textAlternate ;
411412 if ( dataTextAlternate ) {
412- publishButton . innerHTML = dataTextAlternate ;
413+ publishButton . dataset . textStandard = buttonTitle . textContent ;
414+ buttonTitle . textContent = dataTextAlternate ;
415+ }
416+
417+ // Icons in the child element can also be swapped out
418+ const iconElement = publishButton . querySelector ( '.btn__icon' ) ;
419+ if ( ! iconElement ) {
420+ return ;
421+ }
422+ // Find the original font-icon class name (if there was one) so we can toggle back to it
423+ let standardIcon = '' ;
424+ for ( const classname of iconElement . classList ) {
425+ if ( classname . match ( / ^ f o n t - i c o n - / ) ) {
426+ standardIcon = classname . replace ( / ^ f o n t - i c o n - / , '' ) ;
427+ break ;
428+ }
429+ }
430+ if ( standardIcon ) {
431+ publishButton . dataset . iconStandard = standardIcon ;
432+ iconElement . classList . remove ( `font-icon-${ standardIcon } ` ) ;
433+ }
434+ // Add alternate icon
435+ const alternateIcon = publishButton . getAttribute ( 'data-icon-alternate' ) ;
436+ if ( alternateIcon ) {
437+ iconElement . classList . add ( `font-icon-${ alternateIcon } ` ) ;
413438 }
414439 }
415440
@@ -525,7 +550,7 @@ const LinkField = ({
525550 const renderPicker = ! loadingError && ! inHistoryViewer && ! saveRecordFirst && ( isMulti || linkIDs . length === 0 ) ;
526551 const renderModal = ! loadingError && ! saveRecordFirst && Boolean ( editingID ) ;
527552 const loadingErrorText = i18n . _t ( 'LinkField.FAILED_TO_LOAD_LINKS' , 'Failed to load link(s)' ) ;
528- const saveRecordFirstText = isMulti
553+ const saveRecordFirstText = isMulti
529554 ? i18n . _t ( 'LinkField.SAVE_RECORD_FIRST' , 'Cannot add links until the record has been saved' )
530555 : i18n . _t ( 'LinkField.SAVE_RECORD_FIRST_SINGLE' , 'Cannot add link until the record has been saved' ) ;
531556 const links = renderLinks ( ) ;
0 commit comments