-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add content only description for patterns and templates
- Loading branch information
1 parent
2a85977
commit 092fea8
Showing
6 changed files
with
140 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
packages/editor/src/components/block-settings-menu/content-only-settings-menu.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
BlockSettingsMenuControls, | ||
__unstableBlockSettingsMenuFirstItem as BlockSettingsMenuFirstItem, | ||
store as blockEditorStore, | ||
} from '@wordpress/block-editor'; | ||
import { store as coreStore } from '@wordpress/core-data'; | ||
import { __experimentalText as Text, MenuItem } from '@wordpress/components'; | ||
import { useSelect } from '@wordpress/data'; | ||
import { __, sprintf } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { store as editorStore } from '../../store'; | ||
|
||
function ContentOnlySettingsMenuItems( { clientId } ) { | ||
const { entity, onNavigateToEntityRecord } = useSelect( | ||
( select ) => { | ||
const { | ||
getBlockEditingMode, | ||
getBlockParentsByBlockName, | ||
getSettings, | ||
getBlockAttributes, | ||
} = select( blockEditorStore ); | ||
const contentOnly = | ||
getBlockEditingMode( clientId ) === 'contentOnly'; | ||
if ( ! contentOnly ) return {}; | ||
const patternParent = getBlockParentsByBlockName( | ||
clientId, | ||
'core/block', | ||
true | ||
)[ 0 ]; | ||
|
||
let record; | ||
if ( patternParent ) { | ||
record = select( coreStore ).getEntityRecord( | ||
'postType', | ||
'wp_block', | ||
getBlockAttributes( patternParent ).ref | ||
); | ||
} else { | ||
const templateId = select( editorStore ).getCurrentTemplateId(); | ||
if ( templateId ) { | ||
record = select( coreStore ).getEntityRecord( | ||
'postType', | ||
'wp_template', | ||
templateId | ||
); | ||
} | ||
} | ||
return { | ||
entity: record, | ||
onNavigateToEntityRecord: | ||
getSettings().onNavigateToEntityRecord, | ||
}; | ||
}, | ||
[ clientId ] | ||
); | ||
|
||
if ( ! entity ) return null; | ||
|
||
const isPattern = entity.type === 'wp_block'; | ||
|
||
return ( | ||
<> | ||
<BlockSettingsMenuFirstItem> | ||
<Text | ||
variant="muted" | ||
as="p" | ||
className="editor-content-only-settings-menu__description" | ||
> | ||
{ isPattern | ||
? sprintf( | ||
// translators: %s: pattern's title. | ||
__( | ||
'This block is part of the synced pattern: "%s". To move, delete, or edit other properties, you must edit the pattern.' | ||
), | ||
entity.title.raw | ||
) | ||
: sprintf( | ||
// translators: %s: template's title. | ||
__( | ||
'This block is part of the template: "%s". To move, delete, or edit other properties, you must edit the template.' | ||
), | ||
entity.title.rendered | ||
) } | ||
</Text> | ||
</BlockSettingsMenuFirstItem> | ||
<MenuItem | ||
onClick={ () => { | ||
onNavigateToEntityRecord( { | ||
postId: entity.id, | ||
postType: entity.type, | ||
} ); | ||
} } | ||
> | ||
{ isPattern ? __( 'Edit pattern' ) : __( 'Edit template' ) } | ||
</MenuItem> | ||
</> | ||
); | ||
} | ||
|
||
export default function TemplateContentOnlySettingsMenu() { | ||
return ( | ||
<BlockSettingsMenuControls> | ||
{ ( { selectedClientIds } ) => | ||
selectedClientIds.length === 1 && ( | ||
<ContentOnlySettingsMenuItems | ||
clientId={ selectedClientIds[ 0 ] } | ||
/> | ||
) | ||
} | ||
</BlockSettingsMenuControls> | ||
); | ||
} |
4 changes: 4 additions & 0 deletions
4
packages/editor/src/components/block-settings-menu/style.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.editor-content-only-settings-menu__description { | ||
padding: $grid-unit; | ||
min-width: 235px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters