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

Replace SEO settings nofollow toggle with rel text widget #23682

Merged
Merged
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
7 changes: 3 additions & 4 deletions packages/block-library/src/navigation-link/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@
"label": {
"type": "string"
},
"nofollow": {
draganescu marked this conversation as resolved.
Show resolved Hide resolved
"type": "boolean",
"default": false
},
"type": {
"type": "string"
},
"description": {
"type": "string"
},
"rel": {
"type": "string"
},
"id": {
"type": "number"
},
Expand Down
37 changes: 10 additions & 27 deletions packages/block-library/src/navigation-link/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ import { compose } from '@wordpress/compose';
import { createBlock } from '@wordpress/blocks';
import { withDispatch, withSelect } from '@wordpress/data';
import {
ExternalLink,
KeyboardShortcuts,
PanelBody,
Popover,
TextControl,
TextareaControl,
ToggleControl,
ToolbarButton,
ToolbarGroup,
} from '@wordpress/components';
Expand Down Expand Up @@ -60,7 +59,7 @@ function NavigationLinkEdit( {
mergeBlocks,
onReplace,
} ) {
const { label, opensInNewTab, url, nofollow, description } = attributes;
const { label, opensInNewTab, url, description, rel } = attributes;
const link = {
url,
opensInNewTab,
Expand Down Expand Up @@ -161,30 +160,6 @@ function NavigationLinkEdit( {
</ToolbarGroup>
</BlockControls>
<InspectorControls>
<PanelBody title={ __( 'SEO settings' ) }>
<ToggleControl
checked={ nofollow }
onChange={ ( nofollowValue ) => {
setAttributes( { nofollow: nofollowValue } );
} }
label={ __( 'Add nofollow to link' ) }
help={
<Fragment>
{ __(
"Don't let search engines follow this link."
) }
<ExternalLink
className="wp-block-navigation-link__nofollow-external-link"
href={ __(
'https://codex.wordpress.org/Nofollow'
) }
>
{ __( "What's this?" ) }
</ExternalLink>
</Fragment>
}
/>
</PanelBody>
<PanelBody title={ __( 'Link settings' ) }>
<TextareaControl
value={ description || '' }
Expand All @@ -196,6 +171,14 @@ function NavigationLinkEdit( {
'The description will be displayed in the menu if the current theme supports it.'
) }
/>
<TextControl
value={ rel || '' }
onChange={ ( relValue ) => {
setAttributes( { rel: relValue } );
} }
label={ __( 'Link rel' ) }
autoComplete="off"
/>
</PanelBody>
</InspectorControls>
<Block.li
Expand Down
4 changes: 0 additions & 4 deletions packages/block-library/src/navigation-link/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@
}
}

.wp-block-navigation-link__nofollow-external-link {
display: block;
}

// Separator
.wp-block-navigation-link__separator {
margin: $grid-unit-10 0 $grid-unit-10;
Expand Down
45 changes: 45 additions & 0 deletions packages/block-library/src/navigation-link/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
import { __ } from '@wordpress/i18n';
import { mapMarker as icon } from '@wordpress/icons';
import { InnerBlocks } from '@wordpress/block-editor';

/**
* Internal dependencies
Expand All @@ -28,4 +29,48 @@ export const settings = {
},
edit,
save,

deprecated: [
{
isEligible( attributes ) {
return attributes.nofollow;
},

attributes: {
label: {
type: 'string',
},
type: {
type: 'string',
},
nofollow: {
type: 'boolean',
},
description: {
type: 'string',
},
id: {
type: 'number',
},
opensInNewTab: {
type: 'boolean',
default: false,
},
url: {
type: 'string',
},
},

migrate( { nofollow, ...rest } ) {
return {
rel: nofollow ? 'nofollow' : '',
...rest,
};
},

save() {
return <InnerBlocks.Content />;
},
},
],
};
10 changes: 9 additions & 1 deletion packages/block-library/src/navigation-link/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ function render_block_core_navigation_link( $attributes, $content, $block ) {

$html = '<li class="' . esc_attr( $css_classes . ( $has_submenu ? ' has-child' : '' ) ) .
( $is_active ? ' current-menu-item' : '' ) . '"' . $style_attribute . '>' .
'<a class="wp-block-navigation-link__content"';
'<a class="wp-block-navigation-link__content" ';

// Start appending HTML attributes to anchor tag.
if ( isset( $attributes['url'] ) ) {
Expand All @@ -140,6 +140,14 @@ function render_block_core_navigation_link( $attributes, $content, $block ) {
if ( isset( $attributes['opensInNewTab'] ) && true === $attributes['opensInNewTab'] ) {
$html .= ' target="_blank" ';
}

// Start appending HTML attributes to anchor tag.
if ( isset( $attributes['rel'] ) ) {
$html .= ' rel="' . esc_attr( $attributes['rel'] ) . '"';
} elseif ( isset( $attributes['nofollow'] ) && $attributes['nofollow'] ) {
$html .= ' rel="nofollow"';
}

// End appending HTML attributes to anchor tag.

// Start anchor tag content.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"isValid": true,
"attributes": {
"label": "WordPress",
"nofollow": false,
"opensInNewTab": false,
"url": "https://wordpress.org/"
},
Expand Down