Skip to content

Commit

Permalink
Gutenberg: Add a help link directly in our block.
Browse files Browse the repository at this point in the history
To assist users into finding their link for a Google Drive item, a
help link is now added below the URL field.

The help link defaults to our Github wiki page, but developers can
change the link with the 'ray_gdoc_help_url' filter to point to
another page.

See #13.
  • Loading branch information
r-a-y committed Apr 9, 2020
1 parent 099b588 commit c502b26
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
8 changes: 7 additions & 1 deletion block.js
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,13 @@
placeholder: i18n.__( 'Type or Paste URL. Hit Enter to submit.' ),
className: 'components-placeholder__input',
onKeyDown: this.onKeyDown
})
}),
el( 'div', { className: 'components-placeholder__learn-more' },
el( wp.components.ExternalLink, {
href: rayGDriveProps.helpUrl,
children: i18n.__( 'Find out how to find your Google Drive link' )
})
)
)
);
}
Expand Down
28 changes: 28 additions & 0 deletions gdocs-shortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,34 @@ function ray_google_docs_gutenberg_init() {
}
add_action( 'init', 'ray_google_docs_gutenberg_init' );

/**
* Enqueues inline JS for Gutenberg.
*
* Requires at least WordPress 5.2.0.
*
* @since 0.5.0
*/
function ray_google_docs_enqueue_block_assets() {
// If not WP 5.2 or if our Google Drive block is not registered, bail.
if ( ! function_exists( 'wp_is_xml_request' ) || ! WP_Block_Type_Registry::get_instance()->is_registered( 'ray/google-drive' ) ) {
return;
}

/**
* Filter to change the default help URL for the Google Drive block.
*
* @since 0.5.0
*
* @param string $url Help URL.
*/
$help_url = apply_filters( 'ray_gdoc_help_url', 'https://github.com/cuny-academic-commons/google-docs-shortcode/wiki/Sharing-a-Google-Drive-file-and-getting-the-link' );

wp_localize_script( 'ray-gdoc-block', 'rayGDriveProps', array(
'helpUrl' => esc_url_raw( $help_url )
) );
}
add_action( 'enqueue_block_editor_assets', 'ray_google_docs_enqueue_block_assets', 11 );

/**
* Shortcode to embed a Google Doc.
*
Expand Down

0 comments on commit c502b26

Please sign in to comment.