-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Comments Title: Make non-editable #40817
Changes from all commits
d9dd74d
d1580ec
93f155e
873ef31
02ab27a
4ebf66e
da45fac
b323447
ec89431
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import metadata from './block.json'; | ||
|
||
const { attributes, supports } = metadata; | ||
|
||
export default [ | ||
{ | ||
attributes: { | ||
...attributes, | ||
singleCommentLabel: { | ||
type: 'string', | ||
}, | ||
multipleCommentsLabel: { | ||
type: 'string', | ||
}, | ||
}, | ||
supports, | ||
migrate: ( oldAttributes ) => { | ||
/* eslint-disable no-unused-vars */ | ||
const { | ||
singleCommentLabel, | ||
multipleCommentsLabel, | ||
...newAttributes | ||
} = oldAttributes; | ||
/* eslint-enable no-unused-vars */ | ||
return newAttributes; | ||
}, | ||
isEligible: ( { multipleCommentsLabel, singleCommentLabel } ) => | ||
multipleCommentsLabel || singleCommentLabel, | ||
save: () => null, | ||
}, | ||
]; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,17 +10,11 @@ import { | |
AlignmentControl, | ||
BlockControls, | ||
useBlockProps, | ||
PlainText, | ||
InspectorControls, | ||
} from '@wordpress/block-editor'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { __, _n, sprintf } from '@wordpress/i18n'; | ||
import { useEntityProp } from '@wordpress/core-data'; | ||
import { | ||
PanelBody, | ||
ToggleControl, | ||
__experimentalToggleGroupControl as ToggleGroupControl, | ||
__experimentalToggleGroupControlOption as ToggleGroupControlOption, | ||
} from '@wordpress/components'; | ||
import { PanelBody, ToggleControl } from '@wordpress/components'; | ||
import { useState, useEffect } from '@wordpress/element'; | ||
import apiFetch from '@wordpress/api-fetch'; | ||
import { addQueryArgs } from '@wordpress/url'; | ||
|
@@ -31,20 +25,12 @@ import { addQueryArgs } from '@wordpress/url'; | |
import HeadingLevelDropdown from '../heading/heading-level-dropdown'; | ||
|
||
export default function Edit( { | ||
attributes: { | ||
textAlign, | ||
singleCommentLabel, | ||
multipleCommentsLabel, | ||
showPostTitle, | ||
showCommentsCount, | ||
level, | ||
}, | ||
attributes: { textAlign, showPostTitle, showCommentsCount, level }, | ||
setAttributes, | ||
context: { postType, postId }, | ||
} ) { | ||
const TagName = 'h' + level; | ||
const [ commentsCount, setCommentsCount ] = useState(); | ||
const [ editingMode, setEditingMode ] = useState( 'plural' ); | ||
const [ rawTitle ] = useEntityProp( 'postType', postType, 'title', postId ); | ||
const isSiteEditor = typeof postId === 'undefined'; | ||
const blockProps = useBlockProps( { | ||
|
@@ -100,22 +86,6 @@ export default function Edit( { | |
const inspectorControls = ( | ||
<InspectorControls> | ||
<PanelBody title={ __( 'Settings' ) }> | ||
{ isSiteEditor && ( | ||
<ToggleGroupControl | ||
label={ __( 'Editing mode' ) } | ||
onChange={ setEditingMode } | ||
value={ editingMode } | ||
> | ||
<ToggleGroupControlOption | ||
label={ __( 'Singular' ) } | ||
value="singular" | ||
/> | ||
<ToggleGroupControlOption | ||
label={ __( 'Plural' ) } | ||
value="plural" | ||
/> | ||
</ToggleGroupControl> | ||
) } | ||
<ToggleControl | ||
label={ __( 'Show post title' ) } | ||
checked={ showPostTitle } | ||
|
@@ -136,78 +106,52 @@ export default function Edit( { | |
|
||
const postTitle = isSiteEditor ? __( '"Post Title"' ) : `"${ rawTitle }"`; | ||
|
||
const singlePlaceholder = showPostTitle | ||
? __( 'One response to ' ) | ||
: __( 'One response' ); | ||
|
||
const singlePlaceholderNoCount = showPostTitle | ||
? __( 'Response to ' ) | ||
: __( 'Response' ); | ||
|
||
const multiplePlaceholder = showPostTitle | ||
? __( 'responses to ' ) | ||
: __( 'responses' ); | ||
|
||
const multiplePlaceholderNoCount = showPostTitle | ||
? __( 'Responses to ' ) | ||
: __( 'Responses' ); | ||
let placeholder; | ||
if ( showCommentsCount && commentsCount !== undefined ) { | ||
if ( showPostTitle ) { | ||
if ( commentsCount === 1 ) { | ||
/* translators: %s: Post title. */ | ||
placeholder = sprintf( __( 'One response to %s' ), postTitle ); | ||
} else { | ||
placeholder = sprintf( | ||
/* translators: 1: Number of comments, 2: Post title. */ | ||
_n( | ||
'%1$s response to %2$s', | ||
'%1$s responses to %2$s', | ||
commentsCount | ||
), | ||
Comment on lines
+117
to
+122
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
commentsCount, | ||
postTitle | ||
); | ||
} | ||
} else if ( commentsCount === 1 ) { | ||
placeholder = __( 'One response' ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. String exists in Core (per WP 6.0 Beta 4): https://github.com/WordPress/wordpress-develop/blob/04e9728701b3dde0260c7cdebfd726edbe62ac97/src/wp-includes/blocks/comments-title.php#L38 |
||
} else { | ||
placeholder = sprintf( | ||
/* translators: %s: Number of comments. */ | ||
_n( '%s responses', '%s responses', commentsCount ), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. String doesn't exist in Core yet. However, this is arguably needed to fix the issue at the core of this PR (use |
||
commentsCount | ||
); | ||
} | ||
} else if ( showPostTitle ) { | ||
if ( commentsCount === 1 ) { | ||
/* translators: %s: Post title. */ | ||
placeholder = sprintf( __( 'Response to %s' ), postTitle ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. String doesn't exist in Core yet. However, this is arguably needed to fix the issue at the core of this PR (use |
||
} else { | ||
/* translators: %s: Post title. */ | ||
placeholder = sprintf( __( 'Responses to %s' ), postTitle ); | ||
ockham marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} else if ( commentsCount === 1 ) { | ||
placeholder = __( 'Response' ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. String exists in Core (per WP 6.0 Beta 4): https://github.com/WordPress/wordpress-develop/blob/04e9728701b3dde0260c7cdebfd726edbe62ac97/src/wp-includes/blocks/comments-title.php#L36 |
||
} else { | ||
placeholder = __( 'Responses' ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. String exists in Core (per WP 6.0 Beta 3): https://github.com/WordPress/wordpress-develop/blame/04e9728701b3dde0260c7cdebfd726edbe62ac97/src/wp-includes/blocks/comments-title.php#L42 |
||
} | ||
|
||
return ( | ||
<> | ||
{ blockControls } | ||
{ inspectorControls } | ||
<TagName { ...blockProps }> | ||
{ editingMode === 'singular' || commentsCount === 1 ? ( | ||
<> | ||
<PlainText | ||
__experimentalVersion={ 2 } | ||
tagName="span" | ||
aria-label={ | ||
showCommentsCount | ||
? singlePlaceholder | ||
: singlePlaceholderNoCount | ||
} | ||
placeholder={ | ||
showCommentsCount | ||
? singlePlaceholder | ||
: singlePlaceholderNoCount | ||
} | ||
value={ singleCommentLabel } | ||
onChange={ ( newLabel ) => | ||
setAttributes( { | ||
singleCommentLabel: newLabel, | ||
} ) | ||
} | ||
/> | ||
{ showPostTitle ? postTitle : null } | ||
</> | ||
) : ( | ||
<> | ||
{ showCommentsCount ? commentsCount : null } | ||
<PlainText | ||
__experimentalVersion={ 2 } | ||
tagName="span" | ||
aria-label={ | ||
showCommentsCount | ||
? ` ${ multiplePlaceholder }` | ||
: multiplePlaceholderNoCount | ||
} | ||
placeholder={ | ||
showCommentsCount | ||
? ` ${ multiplePlaceholder }` | ||
: multiplePlaceholderNoCount | ||
} | ||
value={ multipleCommentsLabel } | ||
onChange={ ( newLabel ) => | ||
setAttributes( { | ||
multipleCommentsLabel: newLabel, | ||
} ) | ||
} | ||
/> | ||
{ showPostTitle ? postTitle : null } | ||
</> | ||
) } | ||
</TagName> | ||
<TagName { ...blockProps }>{ placeholder }</TagName> | ||
</> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<!-- wp:comments-title {"textAlign":"center","singleCommentLabel":"One reply to ","multipleCommentsLabel":" replies to ","level":4} /--> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[ | ||
{ | ||
"name": "core/comments-title", | ||
"isValid": true, | ||
"attributes": { | ||
"textAlign": "center", | ||
"showPostTitle": true, | ||
"showCommentsCount": true, | ||
"level": 4 | ||
}, | ||
"innerBlocks": [] | ||
} | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[ | ||
{ | ||
"blockName": "core/comments-title", | ||
"attrs": { | ||
"textAlign": "center", | ||
"singleCommentLabel": "One reply to ", | ||
"multipleCommentsLabel": " replies to ", | ||
"level": 4 | ||
}, | ||
"innerBlocks": [], | ||
"innerHTML": "", | ||
"innerContent": [] | ||
} | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<!-- wp:comments-title {"textAlign":"center","level":4} /--> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
String exists in Core: https://github.com/WordPress/wordpress-develop/blob/04e9728701b3dde0260c7cdebfd726edbe62ac97/src/wp-includes/theme-compat/comments.php#L37-L38