Skip to content

Commit

Permalink
Add a back link to header in site editor
Browse files Browse the repository at this point in the history
  • Loading branch information
glendaviesnz committed Nov 27, 2023
1 parent e2e3150 commit 4229cbe
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/block-library/src/block/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"category": "reusable",
"description": "Create and save content to reuse across your site. Update the pattern, and the changes apply everywhere it’s used.",
"keywords": [ "reusable" ],
"usesContext": [ "postId" ],
"textdomain": "default",
"attributes": {
"ref": {
Expand Down
4 changes: 3 additions & 1 deletion packages/block-library/src/block/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export default function ReusableBlockEdit( {
name,
attributes: { ref },
__unstableParentLayout: parentLayout,
context: { postId },
} ) {
const editUrl = useSelect(
( select ) => {
Expand All @@ -96,14 +97,15 @@ export default function ReusableBlockEdit( {
postId: ref,
categoryType: 'pattern',
canvas: 'edit',
refererId: postId,
} );

// For editing link to the site editor if the theme and user permissions support it.
return canUser( 'read', 'templates' ) && isBlockTheme
? siteEditorUrl
: defaultUrl;
},
[ ref ]
[ postId, ref ]
);
useBlockEditingMode( 'syncedPattern' );
const hasAlreadyRendered = useHasRecursion( ref );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { displayShortcut } from '@wordpress/keycodes';
import { store as coreStore } from '@wordpress/core-data';
import { store as editorStore } from '@wordpress/editor';
import { useRef, useState, useEffect } from '@wordpress/element';
import { getQueryArgs } from '@wordpress/url';

/**
* Internal dependencies
Expand Down Expand Up @@ -144,6 +145,13 @@ function TemplateDocumentActions( { className, onBack } ) {
typeIcon = symbol;
}

const { refererId } = getQueryArgs( window.location.href );

if ( ! onBack && refererId ) {
onBack = () =>
( document.location = `post.php?post=${ refererId }&action=edit` );
}

return (
<BaseDocumentActions
className={ classnames( className, {
Expand Down

0 comments on commit 4229cbe

Please sign in to comment.