Skip to content

Commit

Permalink
Move button
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Nov 14, 2024
1 parent 16d5b16 commit 92c918b
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ public function __construct( $post_type ) {
parent::__construct( $post_type );
}

protected function get_available_actions() {
return array();
}

public function register_routes() {
// Lists all templates.
register_rest_route(
Expand Down
1 change: 1 addition & 0 deletions packages/edit-post/src/components/layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ const DESIGN_POST_TYPES = [
'wp_template_part',
'wp_block',
'wp_navigation',
'_wp_static_template',
];

function useEditorStyles( ...additionalStyles ) {
Expand Down
81 changes: 44 additions & 37 deletions packages/edit-site/src/components/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
EditorKeyboardShortcutsRegister,
privateApis as editorPrivateApis,
store as editorStore,
PluginPostStatusInfo,
} from '@wordpress/editor';
import { __, sprintf } from '@wordpress/i18n';
import { store as coreDataStore } from '@wordpress/core-data';
Expand Down Expand Up @@ -217,42 +218,6 @@ export default function EditSiteEditor( { isPostsList = false } ) {
_postType = '_wp_static_template';
}

let customSaveButton;

if ( _isPreviewingTheme ) {
customSaveButton = <SaveButton size="compact" />;
} else if ( _postType === '_wp_static_template' ) {
customSaveButton = (
<Button
__next40pxDefaultSize
variant="primary"
size="compact"
onClick={ async () => {
const currentPost = await registry
.resolveSelect( coreDataStore )
.getEntityRecord( 'postType', _postType, _postId );
const newPost = await registry
.dispatch( coreDataStore )
.saveEntityRecord( 'postType', 'wp_template', {
...currentPost,
id: undefined,
type: 'wp_template',
// It would be great if we could use auto-draft, but
// that doesn't seem to work.
status: 'draft',
} );
history.push( {
postId: newPost.id,
postType: newPost.type,
canvas: 'edit',
} );
} }
>
{ __( 'Duplicate' ) }
</Button>
);
}

const _settings = useMemo( () => {
// To do: whenever canUser cannot update the post, it should
// automatically set the defaultRenderingMode to 'template-locked'.
Expand Down Expand Up @@ -284,7 +249,9 @@ export default function EditSiteEditor( { isPostsList = false } ) {
'show-icon-labels': showIconLabels,
} ) }
styles={ styles }
customSaveButton={ customSaveButton }
customSaveButton={
_isPreviewingTheme && <SaveButton size="compact" />
}
customSavePanel={ _isPreviewingTheme && <SavePanel /> }
forceDisableBlockTools={ ! hasDefaultEditorCanvasView }
forceRemoveBlockTools={
Expand Down Expand Up @@ -376,6 +343,46 @@ export default function EditSiteEditor( { isPostsList = false } ) {
) }
<SiteEditorMoreMenu />
{ supportsGlobalStyles && <GlobalStylesSidebar /> }
{ _postType === '_wp_static_template' && (
<PluginPostStatusInfo>
<Button
__next40pxDefaultSize
variant="primary"
size="compact"
onClick={ async () => {
const currentPost = await registry
.resolveSelect( coreDataStore )
.getEntityRecord(
'postType',
_postType,
_postId
);
const newPost = await registry
.dispatch( coreDataStore )
.saveEntityRecord(
'postType',
'wp_template',
{
...currentPost,
id: undefined,
type: 'wp_template',
// It would be great if we could
// use auto-draft, but that
// doesn't seem to work.
status: 'draft',
}
);
history.push( {
postId: newPost.id,
postType: newPost.type,
canvas: 'edit',
} );
} }
>
{ __( 'Fork Template' ) }
</Button>
</PluginPostStatusInfo>
) }
</Editor>
) }
</>
Expand Down
14 changes: 1 addition & 13 deletions packages/editor/src/components/post-schedule/panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,7 @@ import PostScheduleForm from './index';
import { usePostScheduleLabel } from './label';
import PostPanelRow from '../post-panel-row';
import { store as editorStore } from '../../store';
import {
TEMPLATE_POST_TYPE,
TEMPLATE_PART_POST_TYPE,
PATTERN_POST_TYPE,
NAVIGATION_POST_TYPE,
} from '../../store/constants';

const DESIGN_POST_TYPES = [
TEMPLATE_POST_TYPE,
TEMPLATE_PART_POST_TYPE,
PATTERN_POST_TYPE,
NAVIGATION_POST_TYPE,
];
import { DESIGN_POST_TYPES } from '../../store/constants';

/**
* Renders the Post Schedule Panel component.
Expand Down
14 changes: 1 addition & 13 deletions packages/editor/src/components/post-status/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,7 @@ import {
/**
* Internal dependencies
*/
import {
TEMPLATE_POST_TYPE,
TEMPLATE_PART_POST_TYPE,
PATTERN_POST_TYPE,
NAVIGATION_POST_TYPE,
} from '../../store/constants';
import { DESIGN_POST_TYPES } from '../../store/constants';
import PostPanelRow from '../post-panel-row';
import PostSticky from '../post-sticky';
import { PrivatePostSchedule } from '../post-schedule';
Expand Down Expand Up @@ -74,13 +69,6 @@ export const STATUS_OPTIONS = [
},
];

const DESIGN_POST_TYPES = [
TEMPLATE_POST_TYPE,
TEMPLATE_PART_POST_TYPE,
PATTERN_POST_TYPE,
NAVIGATION_POST_TYPE,
];

export default function PostStatus() {
const { status, date, password, postId, postType, canEdit } = useSelect(
( select ) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/editor/src/components/posts-per-page/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { __experimentalInspectorPopoverHeader as InspectorPopoverHeader } from '
/**
* Internal dependencies
*/
import { TEMPLATE_POST_TYPE } from '../../store/constants';
import { TEMPLATE_TYPES } from '../../store/constants';
import { store as editorStore } from '../../store';
import PostPanelRow from '../post-panel-row';

Expand All @@ -32,7 +32,7 @@ export default function PostsPerPage() {
? getEditedEntityRecord( 'root', 'site' )
: undefined;
return {
isTemplate: getCurrentPostType() === TEMPLATE_POST_TYPE,
isTemplate: TEMPLATE_TYPES.includes( getCurrentPostType() ),
postSlug: getEditedPostAttribute( 'slug' ),
postsPerPage: siteSettings?.posts_per_page || 1,
};
Expand Down
4 changes: 2 additions & 2 deletions packages/editor/src/components/site-discussion/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { __experimentalInspectorPopoverHeader as InspectorPopoverHeader } from '
/**
* Internal dependencies
*/
import { TEMPLATE_POST_TYPE } from '../../store/constants';
import { TEMPLATE_TYPES } from '../../store/constants';
import PostPanelRow from '../post-panel-row';
import { store as editorStore } from '../../store';

Expand Down Expand Up @@ -51,7 +51,7 @@ export default function SiteDiscussion() {
? getEditedEntityRecord( 'root', 'site' )
: undefined;
return {
isTemplate: getCurrentPostType() === TEMPLATE_POST_TYPE,
isTemplate: TEMPLATE_TYPES.includes( getCurrentPostType() ),
postSlug: getEditedPostAttribute( 'slug' ),
allowCommentsOnNewPosts:
siteSettings?.default_comment_status || '',
Expand Down
17 changes: 3 additions & 14 deletions packages/editor/src/components/visual-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ import EditTemplateBlocksNotification from './edit-template-blocks-notification'
import ResizableEditor from '../resizable-editor';
import useSelectNearestEditableBlock from './use-select-nearest-editable-block';
import {
NAVIGATION_POST_TYPE,
DESIGN_POST_TYPES,
PATTERN_POST_TYPE,
TEMPLATE_PART_POST_TYPE,
TEMPLATE_POST_TYPE,
NAVIGATION_POST_TYPE,
TEMPLATE_PART_POST_TYPE,
} from '../../store/constants';
import { useZoomOutModeExit } from './use-zoom-out-mode-exit';

Expand All @@ -51,18 +52,6 @@ const {
useFlashEditableBlocks,
} = unlock( blockEditorPrivateApis );

/**
* These post types have a special editor where they don't allow you to fill the title
* and they don't apply the layout styles.
*/
const DESIGN_POST_TYPES = [
PATTERN_POST_TYPE,
TEMPLATE_POST_TYPE,
NAVIGATION_POST_TYPE,
TEMPLATE_PART_POST_TYPE,
'_wp_static_template',
];

/**
* Given an array of nested blocks, find the first Post Content
* block inside it, recursing through any nesting levels,
Expand Down
7 changes: 7 additions & 0 deletions packages/editor/src/store/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,10 @@ export const GLOBAL_POST_TYPES = [
'wp_block',
'wp_navigation',
];
export const TEMPLATE_TYPES = [ TEMPLATE_POST_TYPE, '_wp_static_template' ];
export const DESIGN_POST_TYPES = [
...TEMPLATE_TYPES,
TEMPLATE_PART_POST_TYPE,
PATTERN_POST_TYPE,
NAVIGATION_POST_TYPE,
];

0 comments on commit 92c918b

Please sign in to comment.