Skip to content

Commit

Permalink
Add a remembers block.
Browse files Browse the repository at this point in the history
  • Loading branch information
StevenDufresne committed Nov 8, 2023
1 parent e241320 commit 318bde6
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 245 deletions.
1 change: 1 addition & 0 deletions source/wp-content/themes/wporg-main-2022/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
require_once __DIR__ . '/src/google-search-embed/index.php';
require_once __DIR__ . '/src/random-heading/index.php';
require_once __DIR__ . '/src/release-tables/index.php';
require_once __DIR__ . '/src/remembers-list/index.php';

/**
* Actions and filters.
Expand Down
252 changes: 7 additions & 245 deletions source/wp-content/themes/wporg-main-2022/patterns/remembers.php

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 2,
"name": "wporg/remembers-list",
"version": "0.1.0",
"title": "Remembers Contributor List",
"category": "design",
"icon": "heading",
"description": "Remembers Contributor List",
"textdomain": "wporg",
"attributes": {
"columns": {
"type": "number",
"default": 3
}
},
"supports": {
"align": true,
"color": {
"background": true,
"text": true
},
"spacing": {
"margin": [ "top", "bottom" ],
"padding": true,
"blockGap": false
},
"typography": {
"fontSize": true,
"lineHeight": true
}
},
"editorScript": "file:./index.js",
"style": "file:./style-index.css"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* WordPress dependencies
*/

import { useBlockProps } from '@wordpress/block-editor';
import { Disabled } from '@wordpress/components';
import ServerSideRender from '@wordpress/server-side-render';

export default function Edit( { attributes, name } ) {
return (
<div { ...useBlockProps() }>
<Disabled>
<ServerSideRender block={ name } attributes={ attributes } />
</Disabled>
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* WordPress dependencies
*/
import { registerBlockType } from '@wordpress/blocks';

/**
* Internal dependencies
*/
import Edit from './edit';
import metadata from './block.json';
import './style.scss';

registerBlockType( metadata.name, {
edit: Edit,
save: () => null,
} );
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php
/**
* Block Name: Remembers Contributor List
* Description: Displays a list of memorialized contributors..
*
* @package wporg
*/

namespace WordPressdotorg\Theme\Main_2022\Remembers_List_Block;

add_action( 'init', __NAMESPACE__ . '\init' );

/**
* Registers the block using the metadata loaded from the `block.json` file.
* Behind the scenes, it registers also all assets so they can be enqueued
* through the block editor in the corresponding context.
*
* @see https://developer.wordpress.org/reference/functions/register_block_type/
*/
function init() {
register_block_type(
dirname( dirname( __DIR__ ) ) . '/build/remembers-list',
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 ) {

// Replace with query
$profiles = [ 'Kim Parsell', 'Alex King', 'Jesse Petersen', 'Efrain Rivera', 'Todrick Moore', 'Alex Mills', 'Joseph Karr O’Connor', 'David de Boer' ];

$columns = $attributes['columns'];
$group_count = ceil( count( $profiles ) / $columns );

$groups = [];
for ( $i = 0; $i < $group_count; $i++ ) {
$groups[] = array_slice( $profiles, $i * $columns, $columns );
}

$block_content = '';
foreach ( $groups as $group ) {
$block_content .= '<!-- wp:columns --><div class="wp-block-columns">';

foreach ( $group as $name ) {
$block_content .= '<!-- wp:column --><div class="wp-block-column">';
$block_content .= '<!-- wp:heading {"textAlign":"center","style":{"spacing":{"margin":{"top":"var:preset|spacing|30","right":"var:preset|spacing|default","bottom":"var:preset|spacing|30","left":"var:preset|spacing|default"}}},"fontSize":"extra-large"} -->';
$block_content .= '<h2 class="wp-block-heading has-text-align-center has-extra-large-font-size" style="margin-top:var(--wp--preset--spacing--30);margin-right:var(--wp--preset--spacing--default);margin-bottom:var(--wp--preset--spacing--30);margin-left:var(--wp--preset--spacing--default)">';
$block_content .= '<em>';
$block_content .= '<a href="https://google.com">' . esc_html( $name ) . '</a>';
$block_content .= '</em>';
$block_content .= '</h2>';
$block_content .= '<!-- /wp:heading -->';
$block_content .= '</div><!-- /wp:column -->';
}

$block_content .= '</div><!-- /wp:columns -->';
}

$wrapper_attributes = get_block_wrapper_attributes();
return sprintf(
'<h1 %1$s>%2$s</h1>',
$wrapper_attributes,
do_blocks( $block_content )
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.wp-block-wporg-remembers-list a {
display: inline-block;
color: inherit;
text-decoration: none;

&:hover {
text-decoration: underline;
}
}

0 comments on commit 318bde6

Please sign in to comment.