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

Home Link: remove ability to edit home link label #32677

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
6 changes: 1 addition & 5 deletions packages/block-library/src/home-link/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
"title": "Home Link",
"description": "Create a link that always points to the homepage of the site. Usually not necessary if there is already a site title link present in the header.",
"textdomain": "default",
"attributes": {
"label": {
"type": "string"
}
},
"attributes": {},
"usesContext": [
"textColor",
"customTextColor",
Expand Down
41 changes: 7 additions & 34 deletions packages/block-library/src/home-link/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,14 @@ import classnames from 'classnames';
/**
* WordPress dependencies
*/
import { RichText, useBlockProps } from '@wordpress/block-editor';
import { __ } from '@wordpress/i18n';
import { useBlockProps } from '@wordpress/block-editor';
import { _x } from '@wordpress/i18n';
import { useSelect } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';
import { useEffect } from '@wordpress/element';

const preventDefault = ( event ) => event.preventDefault();

export default function HomeEdit( {
attributes,
setAttributes,
context,
clientId,
} ) {
export default function HomeEdit( { context, clientId } ) {
const { homeUrl } = useSelect(
( select ) => {
const {
Expand All @@ -46,14 +40,6 @@ export default function HomeEdit( {
},
} );

const { label } = attributes;

useEffect( () => {
if ( label === undefined ) {
setAttributes( { label: __( 'Home' ) } );
}
}, [ clientId, label ] );

return (
<>
<li { ...blockProps }>
Expand All @@ -62,23 +48,10 @@ export default function HomeEdit( {
href={ homeUrl }
onClick={ preventDefault }
>
<RichText
identifier="label"
className="wp-block-home-link__label"
value={ label }
onChange={ ( labelValue ) => {
setAttributes( { label: labelValue } );
} }
aria-label={ __( 'Home link text' ) }
placeholder={ __( 'Add home link' ) }
withoutInteractiveFormatting
allowedFormats={ [
'core/bold',
'core/italic',
'core/image',
'core/strikethrough',
] }
/>
{ _x(
'Home',
'Label for a link that points at the website home, home_url()'
) }
</a>
</li>
</>
Expand Down
5 changes: 1 addition & 4 deletions packages/block-library/src/home-link/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* WordPress dependencies
*/
import { _x } from '@wordpress/i18n';
import { home } from '@wordpress/icons';

/**
Expand All @@ -23,8 +22,6 @@ export const settings = {
save,

example: {
attributes: {
label: _x( 'Home Link', 'block example' ),
},
attributes: {},
},
};
41 changes: 6 additions & 35 deletions packages/block-library/src/home-link/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,43 +121,14 @@ function block_core_home_link_build_li_wrapper_attributes( $context ) {
* @return string Returns the post content with the home url added.
*/
function render_block_core_home_link( $attributes, $content, $block ) {
if ( empty( $attributes['label'] ) ) {
return '';
}

$wrapper_attributes = block_core_home_link_build_li_wrapper_attributes( $block->context );

$html = '<li ' . $wrapper_attributes . '><a class="wp-block-home-link__content"';

// Start appending HTML attributes to anchor tag.
$html .= ' href="' . esc_url( home_url() ) . '"';

// End appending HTML attributes to anchor tag.
$html .= '>';

if ( isset( $attributes['label'] ) ) {
$html .= wp_kses(
$attributes['label'],
array(
'code' => array(),
'em' => array(),
'img' => array(
'scale' => array(),
'class' => array(),
'style' => array(),
'src' => array(),
'alt' => array(),
),
's' => array(),
'span' => array(
'style' => array(),
),
'strong' => array(),
)
);
}

$html .= '</a></li>';
$html = sprintf(
'<li %1$s><a href="%2$s" class="wp-block-home-link__content">%3$s</a></li>',
$wrapper_attributes,
esc_url( home_url() ),
_x( 'Home', 'Label for a link that points at the website home, home_url().' )
);
return $html;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/e2e-tests/fixtures/blocks/core__home-link.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!-- wp:home-link {"label":"Home"} /-->
<!-- wp:home-link /-->
4 changes: 1 addition & 3 deletions packages/e2e-tests/fixtures/blocks/core__home-link.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
"clientId": "_clientId_0",
"name": "core/home-link",
"isValid": true,
"attributes": {
"label": "Home"
},
"attributes": {},
"innerBlocks": [],
"originalContent": ""
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
[
{
"blockName": "core/home-link",
"attrs": {
"label": "Home"
},
"attrs": {},
"innerBlocks": [],
"innerHTML": "",
"innerContent": []
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!-- wp:home-link {"label":"Home"} /-->
<!-- wp:home-link /-->