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

List view: show context menu for content-only blocks in posts #62354

Merged
merged 6 commits into from
Jun 11, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { store as editorStore } from '../../store';
import { unlock } from '../../lock-unlock';

function ContentOnlySettingsMenuItems( { clientId, onClose } ) {
const { entity, onNavigateToEntityRecord } = useSelect(
const { entity, onNavigateToEntityRecord, canEditTemplates } = useSelect(
( select ) => {
const {
getBlockEditingMode,
Expand All @@ -46,19 +46,25 @@ function ContentOnlySettingsMenuItems( { clientId, onClose } ) {
getBlockAttributes( patternParent ).ref
);
} else {
const { getCurrentPostType, getCurrentTemplateId } =
select( editorStore );
const currentPostType = getCurrentPostType();
const { getCurrentTemplateId } = select( editorStore );
const templateId = getCurrentTemplateId();
if ( currentPostType === 'page' && templateId ) {
const { getContentLockingParent } = unlock(
select( blockEditorStore )
);
if ( ! getContentLockingParent( clientId ) && templateId ) {
record = select( coreStore ).getEntityRecord(
'postType',
'wp_template',
templateId
);
}
}
const _canEditTemplates = select( coreStore ).canUser(
'create',
'templates'
);
return {
canEditTemplates: _canEditTemplates,
entity: record,
onNavigateToEntityRecord:
getSettings().onNavigateToEntityRecord,
Expand All @@ -77,6 +83,19 @@ function ContentOnlySettingsMenuItems( { clientId, onClose } ) {
}

const isPattern = entity.type === 'wp_block';
let helpText = isPattern
? __(
'Edit the pattern to move, delete, or make further changes to this block.'
)
: __(
'Edit the template to move, delete, or make further changes to this block.'
);

if ( ! canEditTemplates ) {
helpText = __(
'Only users with permissions to edit the template can move or delete this block'
);
}

return (
<>
Expand All @@ -88,6 +107,7 @@ function ContentOnlySettingsMenuItems( { clientId, onClose } ) {
postType: entity.type,
} );
} }
disabled={ ! canEditTemplates }
>
{ isPattern ? __( 'Edit pattern' ) : __( 'Edit template' ) }
</MenuItem>
Expand All @@ -97,13 +117,7 @@ function ContentOnlySettingsMenuItems( { clientId, onClose } ) {
as="p"
className="editor-content-only-settings-menu__description"
>
{ isPattern
? __(
'Edit the pattern to move, delete, or make further changes to this block.'
)
: __(
'Edit the template to move, delete, or make further changes to this block.'
) }
{ helpText }
</Text>
</>
);
Expand Down
Loading