Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change default "Connected to a custom field" message in bindings #59434

Merged
merged 3 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions packages/block-library/src/image/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
useBlockEditingMode,
} from '@wordpress/block-editor';
import { useEffect, useRef, useState } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { __, sprintf } from '@wordpress/i18n';
import { image as icon, plugins as pluginsIcon } from '@wordpress/icons';
import { store as noticesStore } from '@wordpress/notices';

Expand Down Expand Up @@ -336,7 +336,7 @@ export function ImageEdit( {
} );

// Much of this description is duplicated from MediaPlaceholder.
const { lockUrlControls = false } = useSelect(
const { lockUrlControls = false, lockUrlControlsMessage } = useSelect(
( select ) => {
if ( ! isSingleSelected ) {
return {};
Expand All @@ -351,6 +351,13 @@ export function ImageEdit( {
!! metadata?.bindings?.url &&
( ! blockBindingsSource ||
blockBindingsSource?.lockAttributesEditing ),
lockUrlControlsMessage: blockBindingsSource?.label
? sprintf(
/* translators: %s: Label of the bindings source. */
__( 'Connected to %s' ),
blockBindingsSource.label
)
: __( 'Connected to dynamic data' ),
};
},
[ isSingleSelected ]
Expand Down Expand Up @@ -387,7 +394,7 @@ export function ImageEdit( {
<span
className={ 'block-bindings-media-placeholder-message' }
>
{ __( 'Connected to a custom field' ) }
{ lockUrlControlsMessage }
</span>
) : (
content
Expand Down
36 changes: 20 additions & 16 deletions packages/block-library/src/image/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,9 @@ export default function Image( {
lockUrlControls = false,
lockHrefControls = false,
lockAltControls = false,
lockAltControlsMessage,
lockTitleControls = false,
lockTitleControlsMessage,
lockCaption = false,
} = useSelect(
( select ) => {
Expand Down Expand Up @@ -454,10 +456,24 @@ export default function Image( {
!! altBinding &&
( ! altBindingSource ||
altBindingSource?.lockAttributesEditing ),
lockAltControlsMessage: altBindingSource?.label
? sprintf(
/* translators: %s: Label of the bindings source. */
__( 'Connected to %s' ),
altBindingSource.label
)
: __( 'Connected to dynamic data' ),
lockTitleControls:
!! titleBinding &&
( ! titleBindingSource ||
titleBindingSource?.lockAttributesEditing ),
lockTitleControlsMessage: titleBindingSource?.label
? sprintf(
/* translators: %s: Label of the bindings source. */
__( 'Connected to %s' ),
titleBindingSource.label
)
: __( 'Connected to dynamic data' ),
};
},
[ clientId, isSingleSelected, metadata?.bindings ]
Expand Down Expand Up @@ -557,11 +573,7 @@ export default function Image( {
disabled={ lockAltControls }
help={
lockAltControls ? (
<>
{ __(
'Connected to a custom field'
) }
</>
<>{ lockAltControlsMessage }</>
) : (
<>
<ExternalLink href="https://www.w3.org/WAI/tutorials/images/decision-tree">
Expand Down Expand Up @@ -607,11 +619,7 @@ export default function Image( {
disabled={ lockTitleControls }
help={
lockTitleControls ? (
<>
{ __(
'Connected to a custom field'
) }
</>
<>{ lockTitleControlsMessage }</>
) : (
<>
{ __(
Expand Down Expand Up @@ -652,11 +660,7 @@ export default function Image( {
readOnly={ lockAltControls }
help={
lockAltControls ? (
<>
{ __(
'Connected to a custom field'
) }
</>
<>{ lockAltControlsMessage }</>
) : (
<>
<ExternalLink href="https://www.w3.org/WAI/tutorials/images/decision-tree">
Expand Down Expand Up @@ -694,7 +698,7 @@ export default function Image( {
readOnly={ lockTitleControls }
help={
lockTitleControls ? (
<>{ __( 'Connected to a custom field' ) }</>
<>{ lockTitleControlsMessage }</>
) : (
<>
{ __(
Expand Down
Loading