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

Add Site Title block and support for site options attribute source #16684

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
65 changes: 65 additions & 0 deletions docs/designers-developers/developers/data/data-core.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,22 @@ _Returns_

- `Array`: Records.

<a name="getSiteOptions" href="#getSiteOptions">#</a> **getSiteOptions**

Return site options as they exist locally.

_Related_

- isSiteOptionsDirty

_Parameters_

- _state_ `Object`: Data state.

_Returns_

- `Object`: Site options.

<a name="getThemeSupports" href="#getThemeSupports">#</a> **getThemeSupports**

Return theme supports data in the index.
Expand Down Expand Up @@ -242,6 +258,19 @@ _Returns_

- `boolean`: Whether a request is in progress for an embed preview.

<a name="isSiteOptionsDirty" href="#isSiteOptionsDirty">#</a> **isSiteOptionsDirty**

Return whether the client has local changes to site options which haven't
yet been saved to the server.

_Parameters_

- _state_ `Object`: Data state.

_Returns_

- `boolean`: Whether or not the local site options state is dirty.


<!-- END TOKEN(Autogenerated selectors) -->

Expand Down Expand Up @@ -317,6 +346,18 @@ _Returns_

- `Object`: Action object.

<a name="receiveSiteOptions" href="#receiveSiteOptions">#</a> **receiveSiteOptions**

Returns an action object used in signalling that site options have been received.

_Parameters_

- _siteOptions_ `Object`: Site options.

_Returns_

- `Object`: Action object.

<a name="receiveThemeSupports" href="#receiveThemeSupports">#</a> **receiveThemeSupports**

Returns an action object used in signalling that the index has been received.
Expand Down Expand Up @@ -382,4 +423,28 @@ _Returns_

- `Object`: Updated record.

<a name="saveSiteOptions" href="#saveSiteOptions">#</a> **saveSiteOptions**

Action triggered to save site options.

_Parameters_

- _siteOptions_ `Object`: Site options.

_Returns_

- `Object`: Updated site options.

<a name="updateSiteOptions" href="#updateSiteOptions">#</a> **updateSiteOptions**

Returns an action object used in signalling that site options have been locally updated.

_Parameters_

- _siteOptions_ `Object`: Site options.

_Returns_

- `Object`: Action object.

<!-- END TOKEN(Autogenerated actions) -->
1 change: 1 addition & 0 deletions lib/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ function gutenberg_reregister_core_block_types() {
'rss.php' => 'core/rss',
'shortcode.php' => 'core/shortcode',
'search.php' => 'core/search',
'site-title.php' => 'core/site-title',
'tag-cloud.php' => 'core/tag-cloud',
);

Expand Down
2 changes: 2 additions & 0 deletions packages/block-library/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import * as rss from './rss';
import * as search from './search';
import * as group from './group';
import * as separator from './separator';
import * as siteTitle from './site-title';
import * as shortcode from './shortcode';
import * as spacer from './spacer';
import * as subhead from './subhead';
Expand Down Expand Up @@ -115,6 +116,7 @@ export const registerCoreBlocks = () => {
rss,
search,
separator,
siteTitle,
reusableBlock,
spacer,
subhead,
Expand Down
11 changes: 11 additions & 0 deletions packages/block-library/src/site-title/block.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "core/site-title",
"category": "layout",
"attributes": {
"title": {
"type": "string",
"source": "option",
"option": "title"
}
}
}
22 changes: 22 additions & 0 deletions packages/block-library/src/site-title/edit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* WordPress dependencies
*/
import { PlainText } from '@wordpress/editor';
import { __ } from '@wordpress/i18n';

function SiteTitleEdit( { attributes, setAttributes } ) {
const { title } = attributes;

return (
<div className="wp-block-site-title">
<PlainText
value={ title }
onChange={ ( newTitle ) => setAttributes( { title: newTitle } ) }
placeholder={ __( 'Site Title' ) }
aria-label={ __( 'Site Title' ) }
/>
</div>
);
}

export default SiteTitleEdit;
20 changes: 20 additions & 0 deletions packages/block-library/src/site-title/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import edit from './edit';
import metadata from './block.json';

const { name } = metadata;

export { metadata, name };

export const settings = {
title: __( 'Site Title' ),
description: __( '' ),
edit,
};
31 changes: 31 additions & 0 deletions packages/block-library/src/site-title/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
/**
* Server-side rendering of the `core/site-title` block.
*
* @package WordPress
*/

/**
* Renders the `core/site-title` block on server.
*
* @param array $attributes The block attributes.
*
* @return string Returns a rendering of the the site title.
*/
function render_block_core_site_title( $attributes ) {
return sprintf( '<h1>%s</h1>', get_bloginfo( 'name' ) );
}

/**
* Registers the `core/site-title` block on server.
*/
function register_block_core_site_title() {
register_block_type(
'core/site-title',
array(
'attributes' => array(),
'render_callback' => 'render_block_core_site_title',
)
);
}
add_action( 'init', 'register_block_core_site_title' );
3 changes: 3 additions & 0 deletions packages/block-library/src/site-title/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.wp-block-site-title {
font-size: 300%;
}
1 change: 1 addition & 0 deletions packages/block-library/src/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
@import "./rss/style.scss";
@import "./search/style.scss";
@import "./separator/style.scss";
@import "./site-title/style.scss";
@import "./spacer/style.scss";
@import "./subhead/style.scss";
@import "./table/style.scss";
Expand Down
65 changes: 65 additions & 0 deletions packages/core-data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,18 @@ _Returns_

- `Object`: Action object.

<a name="receiveSiteOptions" href="#receiveSiteOptions">#</a> **receiveSiteOptions**

Returns an action object used in signalling that site options have been received.

_Parameters_

- _siteOptions_ `Object`: Site options.

_Returns_

- `Object`: Action object.

<a name="receiveThemeSupports" href="#receiveThemeSupports">#</a> **receiveThemeSupports**

Returns an action object used in signalling that the index has been received.
Expand Down Expand Up @@ -175,6 +187,30 @@ _Returns_

- `Object`: Updated record.

<a name="saveSiteOptions" href="#saveSiteOptions">#</a> **saveSiteOptions**

Action triggered to save site options.

_Parameters_

- _siteOptions_ `Object`: Site options.

_Returns_

- `Object`: Updated site options.

<a name="updateSiteOptions" href="#updateSiteOptions">#</a> **updateSiteOptions**

Returns an action object used in signalling that site options have been locally updated.

_Parameters_

- _siteOptions_ `Object`: Site options.

_Returns_

- `Object`: Action object.

<!-- END TOKEN(Autogenerated actions) -->

## Selectors
Expand Down Expand Up @@ -330,6 +366,22 @@ _Returns_

- `Array`: Records.

<a name="getSiteOptions" href="#getSiteOptions">#</a> **getSiteOptions**

Return site options as they exist locally.

_Related_

- isSiteOptionsDirty

_Parameters_

- _state_ `Object`: Data state.

_Returns_

- `Object`: Site options.

<a name="getThemeSupports" href="#getThemeSupports">#</a> **getThemeSupports**

Return theme supports data in the index.
Expand Down Expand Up @@ -419,6 +471,19 @@ _Returns_

- `boolean`: Whether a request is in progress for an embed preview.

<a name="isSiteOptionsDirty" href="#isSiteOptionsDirty">#</a> **isSiteOptionsDirty**

Return whether the client has local changes to site options which haven't
yet been saved to the server.

_Parameters_

- _state_ `Object`: Data state.

_Returns_

- `boolean`: Whether or not the local site options state is dirty.


<!-- END TOKEN(Autogenerated selectors) -->

Expand Down
45 changes: 45 additions & 0 deletions packages/core-data/src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,51 @@ export function receiveThemeSupports( themeSupports ) {
};
}

/**
* Returns an action object used in signalling that site options have been received.
*
* @param {Object} siteOptions Site options.
*
* @return {Object} Action object.
*/
export function receiveSiteOptions( siteOptions ) {
return {
type: 'RECEIVE_SITE_OPTIONS',
siteOptions,
};
}

/**
* Returns an action object used in signalling that site options have been locally updated.
*
* @param {Object} siteOptions Site options.
*
* @return {Object} Action object.
*/
export function updateSiteOptions( siteOptions ) {
return {
type: 'UPDATE_SITE_OPTIONS',
siteOptions,
};
}

/**
* Action triggered to save site options.
*
* @param {Object} siteOptions Site options.
*
* @return {Object} Updated site options.
*/
export function* saveSiteOptions( siteOptions ) {
const updatedOptions = yield apiFetch( {
path: '/wp/v2/settings',
method: 'POST',
data: siteOptions,
} );
yield receiveSiteOptions( updatedOptions );
return updatedOptions;
}

/**
* Returns an action object used in signalling that the preview data for
* a given URl has been received.
Expand Down
Loading