-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Theme: Add blocks and block binding for pledge details
See #276
- Loading branch information
Showing
11 changed files
with
356 additions
and
15 deletions.
There are no files selected for viewing
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
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
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,63 @@ | ||
<?php | ||
/** | ||
* Set up custom block bindings. | ||
*/ | ||
|
||
namespace WordPressdotorg\Theme\FiveForTheFuture_2024\Block_Bindings; | ||
|
||
use function WordPressDotOrg\FiveForTheFuture\PledgeMeta\get_pledge_meta; | ||
use function WordPressDotOrg\FiveForTheFuture\XProfile\get_aggregate_contributor_data_for_pledge; | ||
|
||
add_action( 'init', __NAMESPACE__ . '\register_block_bindings' ); | ||
|
||
/** | ||
* Register block bindings. | ||
* | ||
* This registers some sources which can be used to dynamically inject content | ||
* into block text or attributes. | ||
*/ | ||
function register_block_bindings() { | ||
register_block_bindings_source( | ||
'wporg-5ftf/pledge-meta', | ||
array( | ||
'label' => 'Pledge meta', | ||
'uses_context' => [ 'postId' ], | ||
'get_value_callback' => __NAMESPACE__ . '\get_meta_binding_value', | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* Callback to provide the binding value. | ||
*/ | ||
function get_meta_binding_value( $args, $block ) { | ||
if ( ! isset( $args['key'] ) ) { | ||
return ''; | ||
} | ||
|
||
$data = get_pledge_meta( $block->context['postId'] ); | ||
if ( empty( $data ) ) { | ||
return ''; | ||
} | ||
|
||
switch ( $args['key'] ) { | ||
case 'org-url-link': | ||
return sprintf( | ||
'<a href="%s" rel="nofollow">%s</a>', | ||
esc_url( $data['org-url'] ), | ||
esc_html( $data['org-domain'] ) | ||
); | ||
case 'org-contribution-details': | ||
$contribution_data = get_aggregate_contributor_data_for_pledge( $block->context['postId'] ); | ||
return sprintf( | ||
__( '%1$s sponsors %2$s for a total of <strong>%3$s hours</strong> per week across <strong>%4$d teams</strong>.', 'wporg-5ftf' ), | ||
get_the_title( $block->context['postId'] ), | ||
sprintf( | ||
_n( '<strong>%d contributor</strong>', '<strong>%d contributors</strong>', $contribution_data['contributors'], 'wporg-5ftf' ), | ||
number_format_i18n( absint( $contribution_data['contributors'] ) ) | ||
), | ||
number_format_i18n( absint( $contribution_data['hours'] ) ), | ||
count( $contribution_data['teams'] ) | ||
); | ||
} | ||
} |
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,93 @@ | ||
<?php | ||
/** | ||
* Title: Pledge Detail | ||
* Slug: wporg-5ftf-2024/single-5ftf-pledge | ||
* Inserter: no | ||
*/ | ||
|
||
?> | ||
<!-- wp:group {"align":"wide","style":{"spacing":{"margin":{"bottom":"var:preset|spacing|40"},"blockGap":"var:preset|spacing|40"}},"layout":{"type":"flex","flexWrap":"nowrap"}} --> | ||
<div class="wp-block-group alignwide" style="margin-bottom:var(--wp--preset--spacing--40)"> | ||
<!-- wp:group {"style":{"border":{"style":"solid","width":"1px","color":"#d9d9d9","radius":"2px"}},"backgroundColor":"light-grey-2","layout":{"type":"constrained"}} --> | ||
<div class="wp-block-group has-border-color has-light-grey-2-background-color has-background" style="border-color:#d9d9d9;border-style:solid;border-width:1px;border-radius:2px"> | ||
<!-- wp:post-featured-image {"aspectRatio":"1","width":"110px","scale":"contain"} /--> | ||
</div> | ||
<!-- /wp:group --> | ||
|
||
<!-- wp:group {"style":{"spacing":{"blockGap":"var:preset|spacing|10"}},"layout":{"type":"flex","orientation":"vertical"}} --> | ||
<div class="wp-block-group"> | ||
<!-- wp:post-title {"level":1,"style":{"spacing":{"margin":{"top":"0"}}}} /--> | ||
|
||
<!-- wp:group {"layout":{"type":"flex","flexWrap":"nowrap"}} --> | ||
<div class="wp-block-group"> | ||
<!-- wp:paragraph {"metadata":{"bindings":{"content":{"source":"wporg-5ftf/pledge-meta","args":{"key":"org-url-link"}}}}} --> | ||
<p>https://url.com</p> | ||
<!-- /wp:paragraph --> | ||
|
||
<!-- wp:paragraph {"style":{"elements":{"link":{"color":{"text":"var:preset|color|charcoal-5"}}}},"textColor":"charcoal-5","fontSize":"extra-small"} --> | ||
<p class="has-charcoal-5-color has-text-color has-link-color has-extra-small-font-size">•</p> | ||
<!-- /wp:paragraph --> | ||
|
||
<!-- wp:paragraph --> | ||
<p><?php esc_html_e( 'This organization contributes 5% of their resources to the WordPress project.', 'wporg-5ftf' ); ?></p> | ||
<!-- /wp:paragraph --> | ||
</div> | ||
<!-- /wp:group --> | ||
</div> | ||
<!-- /wp:group --> | ||
</div> | ||
<!-- /wp:group --> | ||
|
||
<!-- wp:columns {"align":"wide","style":{"spacing":{"blockGap":{"left":"var:preset|spacing|60"}}}} --> | ||
<div class="wp-block-columns alignwide"> | ||
<!-- wp:column {"width":"60%"} --> | ||
<div class="wp-block-column" style="flex-basis:60%"> | ||
<!-- wp:post-content /--> | ||
|
||
<!-- wp:separator {"className":"is-style-wide","style":{"spacing":{"margin":{"top":"var:preset|spacing|30","bottom":"var:preset|spacing|20"}}},"backgroundColor":"black-opacity-15"} --> | ||
<hr class="wp-block-separator has-text-color has-black-opacity-15-color has-alpha-channel-opacity has-black-opacity-15-background-color has-background is-style-wide" style="margin-top:var(--wp--preset--spacing--30);margin-bottom:var(--wp--preset--spacing--20)"/> | ||
<!-- /wp:separator --> | ||
|
||
<!-- wp:buttons {"style":{"spacing":{"blockGap":"5px"}}} --> | ||
<div class="wp-block-buttons"> | ||
<!-- wp:button --> | ||
<div class="wp-block-button is-style-text is-destructive is-small"> | ||
<a class="wp-block-button__link wp-element-button" href="<?php echo esc_url( home_url( '/report/' ) ); ?>"><?php esc_html_e( 'Report a problem', 'wporg-5ftf' ); ?></a> | ||
</div> | ||
<!-- /wp:button --> | ||
|
||
<!-- wp:wporg/pledge-edit-button /--> | ||
</div> | ||
<!-- /wp:buttons --> | ||
</div> | ||
<!-- /wp:column --> | ||
|
||
<!-- wp:column {"width":"40%"} --> | ||
<div class="wp-block-column" style="flex-basis:40%"> | ||
<!-- wp:heading {"style":{"spacing":{"margin":{"top":"0"}},"typography":{"fontStyle":"normal","fontWeight":"600"}},"fontSize":"heading-5","fontFamily":"inter"} --> | ||
<h2 class="wp-block-heading has-inter-font-family has-heading-5-font-size" style="margin-top:0;font-style:normal;font-weight:600">Contributions</h2> | ||
<!-- /wp:heading --> | ||
|
||
<!-- wp:paragraph {"metadata":{"bindings":{"content":{"source":"wporg-5ftf/pledge-meta","args":{"key":"org-contribution-details"}}}}} --> | ||
<p></p> | ||
<!-- /wp:paragraph --> | ||
|
||
<!-- wp:paragraph --> | ||
<p>{Team list}</p> | ||
<!-- /wp:paragraph --> | ||
</div> | ||
<!-- /wp:column --> | ||
</div> | ||
<!-- /wp:columns --> | ||
|
||
<!-- wp:group {"align":"wide","layout":{"type":"default"}} --> | ||
<div class="wp-block-group alignwide"> | ||
<!-- wp:heading --> | ||
<h2 class="wp-block-heading">Contributors</h2> | ||
<!-- /wp:heading --> | ||
|
||
<!-- wp:paragraph --> | ||
<p>{Avatar list}</p> | ||
<!-- /wp:paragraph --> | ||
</div> | ||
<!-- /wp:group --> |
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/pledge-edit-button", | ||
"version": "0.1.0", | ||
"title": "Edit pledge button", | ||
"category": "design", | ||
"icon": "", | ||
"description": "Render the pledge edit button and form.", | ||
"textdomain": "wporg", | ||
"supports": { | ||
"html": false | ||
}, | ||
"usesContext": [ "postId", "postType" ], | ||
"editorScript": "file:./index.js", | ||
"style": "file:./style-index.css" | ||
} |
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,28 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { registerBlockType } from '@wordpress/blocks'; | ||
import { useBlockProps } from '@wordpress/block-editor'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import metadata from './block.json'; | ||
import './style.scss'; | ||
|
||
const Edit = () => { | ||
const blockProps = useBlockProps(); | ||
return ( | ||
<div { ...blockProps }> | ||
<button> | ||
<span className="dashicons dashicons-edit" aria-hidden="true"></span> | ||
Edit Pledge | ||
</button> | ||
</div> | ||
); | ||
}; | ||
|
||
registerBlockType( metadata.name, { | ||
edit: Edit, | ||
save: () => null, | ||
} ); |
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,53 @@ | ||
<?php | ||
/** | ||
* Block Name: Edit pledge button | ||
* Description: Render the pledge edit button and form. | ||
* | ||
* @package wporg | ||
*/ | ||
|
||
namespace WordPressdotorg\Theme\FiveForTheFuture_2024\Pledge_Edit_Button_Block; | ||
|
||
use WP_HTML_Tag_Processor; | ||
|
||
defined( 'WPINC' ) || die(); | ||
|
||
add_action( 'init', __NAMESPACE__ . '\init' ); | ||
|
||
/** | ||
* Register the block. | ||
*/ | ||
function init() { | ||
register_block_type( | ||
dirname( dirname( __DIR__ ) ) . '/build/pledge-edit-button', | ||
array( | ||
'render_callback' => __NAMESPACE__ . '\render', | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* Render the block content. | ||
* | ||
* @param array $attributes Block attributes. | ||
* @param string $content Block default content. | ||
* @param WP_Block $block Block instance. | ||
* | ||
* @return string Returns the block markup. | ||
*/ | ||
function render( $attributes, $content, $block ) { | ||
ob_start(); | ||
do_action( 'pledge_footer' ); | ||
$content = ob_get_clean(); | ||
|
||
$html = new WP_HTML_Tag_Processor( $content ); | ||
$html->next_tag( 'button' ); | ||
$html->add_class( 'wp-block-button__link' ); | ||
|
||
$wrapper_attributes = get_block_wrapper_attributes( [ 'class' => 'wp-block-button is-style-text is-small' ]); | ||
return sprintf( | ||
'<div %s>%s</div>', | ||
$wrapper_attributes, | ||
$html->get_updated_html() | ||
); | ||
} |
Oops, something went wrong.