-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Events: Convert landing page patterns to a block (#1077)
This prevents them from being loaded on pages where they aren't used.
- Loading branch information
Showing
10 changed files
with
112 additions
and
54 deletions.
There are no files selected for viewing
File renamed without changes.
52 changes: 52 additions & 0 deletions
52
...ml/wp-content/themes/wporg-events-2023/blocks/events-landing-page/events-landing-page.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace WordPressdotorg\Events_2023; | ||
defined( 'WPINC' ) || die(); | ||
|
||
require_once __DIR__ . '/event-getters.php'; | ||
|
||
add_action( 'init', __NAMESPACE__ . '\register_blocks' ); | ||
|
||
|
||
/** | ||
* Register blocks. | ||
*/ | ||
function register_blocks(): void { | ||
register_block_type( | ||
__DIR__ . '/build/block.json', | ||
array( | ||
'render_callback' => __NAMESPACE__ . '\render_events_landing_page', | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* Render the output of the Events Landing Page block. | ||
*/ | ||
function render_events_landing_page( array $block_attributes, string $content ): string { | ||
switch ( $block_attributes['events'] ) { | ||
case 'all-upcoming': | ||
$map_options = array( | ||
'id' => 'all-upcoming-events', | ||
'markers' => get_all_upcoming_events(), | ||
); | ||
break; | ||
|
||
case 'city': | ||
// Can't use `$wp->request` because Gutenberg calls this on `init`, before `parse_request`. | ||
// @todo That was true when this was part of a pattern, but it isn't now that this is a block. We can | ||
// maybe pass `$wp->request` to `normalize_request_uri()` now, or maybe remove that function entirely. | ||
$request_uri = normalize_request_uri( $_SERVER['REQUEST_URI'], $_SERVER['QUERY_STRING'] ); | ||
|
||
$map_options = array( | ||
'id' => 'city-landing-page', | ||
'markers' => get_city_landing_page_events( $request_uri ), | ||
); | ||
break; | ||
|
||
default: | ||
return 'No events available'; | ||
} | ||
|
||
return do_blocks( '<!-- wp:wporg/google-map '. wp_json_encode( $map_options ) .' /-->' ); | ||
} |
13 changes: 13 additions & 0 deletions
13
public_html/wp-content/themes/wporg-events-2023/blocks/events-landing-page/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"name": "events-landing-page", | ||
"version": "0.0.1", | ||
"description": "Gather events for the different landing pages, and pass them to the Google Map block to be displayed.", | ||
"main": "index.js", | ||
"scripts": { | ||
"start": "wp-scripts start", | ||
"build": "wp-scripts build" | ||
}, | ||
"devDependencies": { | ||
"@wordpress/scripts": "^26.13.0" | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
public_html/wp-content/themes/wporg-events-2023/blocks/events-landing-page/src/block.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"$schema": "https://schemas.wp.org/trunk/block.json", | ||
"apiVersion": 2, | ||
"name": "wporg/events-landing-page", | ||
"title": "Events Landing Page", | ||
"icon": "admin-site-alt", | ||
"category": "widgets", | ||
"description": "Gather events for the different landing pages, and pass them to the Google Map block to be displayed.", | ||
"textdomain": "wporg", | ||
"attributes": { | ||
"events": { | ||
"type": "string", | ||
"default": "" | ||
} | ||
}, | ||
"editorScript": "file:./index.js" | ||
} |
27 changes: 27 additions & 0 deletions
27
public_html/wp-content/themes/wporg-events-2023/blocks/events-landing-page/src/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { registerBlockType } from '@wordpress/blocks'; | ||
import { Placeholder } from '@wordpress/components'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import metadata from './block.json'; | ||
|
||
function Edit() { | ||
return ( | ||
<Placeholder | ||
instructions={ __( | ||
'This is a placeholder for the editor. Data is supplied to this block via the template that includes it.', | ||
'wordcamporg' | ||
) } | ||
label={ __( 'Events Landing Page', 'wordcamporg' ) } | ||
/> | ||
); | ||
} | ||
|
||
registerBlockType( metadata.name, { | ||
edit: Edit, | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 0 additions & 27 deletions
27
public_html/wp-content/themes/wporg-events-2023/patterns/city-landing-page-map.php
This file was deleted.
Oops, something went wrong.
24 changes: 0 additions & 24 deletions
24
public_html/wp-content/themes/wporg-events-2023/patterns/front-page-map.php
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters