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

Allow to set custom Font sizes on Group-, Heading- and Paragraph-Blocks #23

Merged
merged 10 commits into from
Oct 11, 2023
File renamed without changes.
6 changes: 3 additions & 3 deletions build/label-printing/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace Figuren_Theater\Label_Printing\Blocks\Printing;

use Figuren_Theater\Label_Printing\Patterns;
use Figuren_Theater\Network\Blocks\Patterns as BlocksPatterns;

/**
* Render callback of the 'figuren-theater/label-printing' block.
Expand Down Expand Up @@ -53,9 +54,8 @@ function render( array $attributes ) : string {
$attributes['orientation']
);

// Generate the pattern slug from label.
$pattern_slug = 'figuren-theater/label-view-a4-' . $label->ID;

// Get the pattern slug from label.
$pattern_slug = Patterns\Generator::get_pattern_name( (int) $label->ID );
// Prepare block-pattern with the specified pattern slug for rendering.
$pattern = \do_blocks( '<!-- wp:pattern {"slug":"' . $pattern_slug . '"} -->' );

Expand Down
2 changes: 1 addition & 1 deletion build/label-printing/label-printing.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-element', 'wp-i18n', 'wp-server-side-render'), 'version' => '97a2c4c3c7e5833c161a');
<?php return array('dependencies' => array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-server-side-render'), 'version' => 'd3f5d2cb72afc51db587');
2 changes: 1 addition & 1 deletion build/label-printing/label-printing.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions inc/block-variations/namespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ function register_asset( string $asset ) : void {

$dir = Label_Printing\DIRECTORY;

$script_asset_path = "$dir/build/$asset.asset.php";
$path = "build/$asset";

$script_asset_path = "$dir/$path/$asset.asset.php";

$error_message = "You need to run `npm start` or `npm run build` for the '$asset' block-asset first.";

Expand All @@ -67,7 +69,7 @@ function register_asset( string $asset ) : void {
}
}

$index_js = "build/$asset.js";
$index_js = "$path/$asset.js";
$script_asset = require $script_asset_path; // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingVariable

wp_register_script(
Expand All @@ -80,7 +82,7 @@ function register_asset( string $asset ) : void {
wp_set_script_translations(
"label-printing--$asset",
'label-printing',
Label_Printing\DIRECTORY . '/languages'
"$dir/languages"
);
}

Expand Down
1 change: 1 addition & 0 deletions inc/blocks/namespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function register() :void {
*/
function bootstrap() :void {
register_blocks();

}

/**
Expand Down
23 changes: 23 additions & 0 deletions inc/patterns/class-generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,29 @@ public function __construct( Label $label ) {
$this->label = $label;
}

/**
* Generate the pattern slug from the label post_ID.
*
* @param int $id Post ID of the wp_block post.
*
* @return string Namespaced pattern slug|name including the labels post_ID.
*/
public static function get_pattern_name( int $id ) : string {
return "figuren-theater/label-view-a4-$id";
}

/**
* Get human readable title of block pattern
* (currently invisible in the UI)
*
* @param string $label_name Human readable name of the label.
*
* @return string Human readable name of the block-pattern.
*/
public static function get_pattern_title( string $label_name ) : string {
return "A4 view of $label_name Label";
}

/**
* Get full html of customized printing-label-sheet pattern,
* using a 'core/group' block with one of two custom block-styles.
Expand Down
132 changes: 77 additions & 55 deletions inc/patterns/class-label-store.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,81 +193,103 @@ function( array $bootstrap_label ) : Label {
}

/**
* Get static defaults
*
* @example
* [
* [
* 'name' => 'A6 Landscape (4 Stück)',
* 'width' => 148,
* 'height' => 105,
* 'a4_border_tb' => 0,
* 'a4_border_lr' => 0,
* 'orientation' => 'landscape',
* ],
* [
* 'name' => 'A6 Landscape',
* 'width' => 148,
* 'height' => 90,
* 'a4_border_tb' => 15,
* 'a4_border_lr' => 0,
* 'orientation' => 'landscape',
* ],
* [
* 'name' => 'A8 Portrait',
* 'width' => 52.5,
* 'height' => 74,
* 'a4_border_tb' => 0,
* 'a4_border_lr' => 0,
* 'orientation' => 'portrait',
* ],
* [
* 'name' => 'A8 Landscape',
* 'width' => 74,
* 'height' => 52.5,
* 'a4_border_tb' => 0,
* 'a4_border_lr' => 0,
* 'orientation' => 'landscape',
* ],
* ];
* Get static default labels.
*
* @return array<int, array<string, string|int|float>> An array of static default label configurations.
*/
public static function get_bootstrap_labels() : array {
return [
$bootstrap_labels = [
[
'name' => 'A6 Landscape (4 Stück)',
'name' => 'A6 Landscape',
'width' => 148,
'height' => 105,
'a4_border_tb' => 0,
'a4_border_lr' => 0,
'orientation' => 'landscape',
],
[
'name' => 'niceday (8 Stück)',
'width' => 105,
'height' => 74,
'a4_border_tb' => 0,
'name' => 'A6 Landscape (with Top-Bottom-Borders)',
'width' => 148,
'height' => 90,
'a4_border_tb' => 15,
'a4_border_lr' => 0,
'orientation' => 'portrait',
'orientation' => 'landscape',
],
[
'name' => 'HERMA Neon No. 5147 (8 Stück)',
'width' => 96,
'height' => 67,
'a4_border_tb' => 14,
'a4_border_lr' => 9,
'name' => 'A8 Portrait',
'width' => 52.5,
'height' => 74,
'a4_border_tb' => 0,
'a4_border_lr' => 0,
'orientation' => 'portrait',
],
[
'name' => 'LABELident (64 Stück)',
'width' => 48,
'height' => 17,
'a4_border_tb' => 13,
'a4_border_lr' => 8,
'orientation' => 'portrait',
'name' => 'A8 Landscape',
'width' => 74,
'height' => 52.5,
'a4_border_tb' => 0,
'a4_border_lr' => 0,
'orientation' => 'landscape',
],
];

/**
* Add your own labels or just adjust the default ones using this filter.
*
* @hook Figuren_Theater\Label_Printing\Patterns\bootstrap_labels
* @since 0.2.0
*
* @phpstan-ignore-next-line phpDoc.parseError
* @param {array} $bootstrap_labels List of Labels (an array of arrays) that will be inserted into the DB on import by default.
*
* @phpstan-ignore-next-line phpDoc.parseError
* @return {array} List of Labels (an array of arrays) that will be inserted into the DB on import.
*
* @example <caption>Add your own or adjust the default labels.</caption>
* \add_filter(
* 'Figuren_Theater\Label_Printing\Patterns\bootstrap_labels',
* function( array $default_labels ) : array {
* return [
* [
* 'name' => 'A6 Landscape (4 Stück)',
* 'width' => 148,
* 'height' => 105,
* 'a4_border_tb' => 0,
* 'a4_border_lr' => 0,
* 'orientation' => 'landscape',
* ],
* [
* 'name' => 'niceday (8 Stück)',
* 'width' => 105,
* 'height' => 74,
* 'a4_border_tb' => 0,
* 'a4_border_lr' => 0,
* 'orientation' => 'portrait',
* ],
* [
* 'name' => 'HERMA Neon No. 5147 (8 Stück)',
* 'width' => 96,
* 'height' => 67,
* 'a4_border_tb' => 14,
* 'a4_border_lr' => 9,
* 'orientation' => 'portrait',
* ],
* [
* 'name' => 'LABELident (64 Stück)',
* 'width' => 48,
* 'height' => 17,
* 'a4_border_tb' => 13,
* 'a4_border_lr' => 8,
* 'orientation' => 'portrait',
* ],
* ];
* }
* );
*/
return \apply_filters(
__NAMESPACE__ . '\\bootstrap_labels',
$bootstrap_labels
);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions inc/patterns/namespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ function register_block_patterns( Label $label ) : void {

// Register block-pattern to WordPress.
\register_block_pattern(
'figuren-theater/label-view-a4-' . $label->post_ID,
$generator::get_pattern_name( $label->post_ID ),
[
'title' => 'A4 view of ' . $label->name . ' Label',
'title' => $generator::get_pattern_title( $label->name ),
'content' => $generator->get_markup(),
'description' => _x( 'This is an overview block pattern for printing labels.', 'Block pattern description', 'label-printing' ),
'viewportWidth' => 1500,
Expand Down
Loading