Skip to content

Commit

Permalink
List view: show context menu for content-only blocks in posts (WordPr…
Browse files Browse the repository at this point in the history
…ess#62354)

* Ensure the Edit template context menu is shown in the post editor/site editor pages by checking only for a templateId.
Previously it was only shown for pages and there was no check if the user can edit template.
Show a not-very-pretty dialogue box where a user cannot edit a template.

* Check for an entity before showing the canUser message.

* Rename variable
Move canUser fallback component beneath existing entity check block

* Use existing component but disable the edit button and update the copy

* Check for content blocks

* Use `getContentLockingParent`

Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>
Co-authored-by: talldan <talldanwp@git.wordpress.org>
Co-authored-by: kevin940726 <kevin940726@git.wordpress.org>
Co-authored-by: andrewserong <andrewserong@git.wordpress.org>
Co-authored-by: ellatrix <ellatrix@git.wordpress.org>
  • Loading branch information
6 people authored and patil-vipul committed Jun 17, 2024
1 parent d77e0b5 commit 32fa0fa
Showing 1 changed file with 26 additions and 12 deletions.
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

0 comments on commit 32fa0fa

Please sign in to comment.