-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
<?php return array('dependencies' => array('wp-blocks', 'wp-i18n'), 'version' => 'eb65da5231c4319dc505'); | ||
<?php return array('dependencies' => array('wp-blocks', 'wp-i18n'), 'version' => '5c7e8717e8026da41a9a'); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"$schema": "https://schemas.wp.org/trunk/block.json", | ||
"apiVersion": 3, | ||
"name": "figuren-theater/label-printing", | ||
"version": "0.1.0", | ||
"title": "Label Printing", | ||
"category": "widgets", | ||
"icon": "grid-view", | ||
"description": "Make labels now.", | ||
"example": {}, | ||
"attributes": { | ||
"wpLabelPost": { | ||
"type": "number", | ||
"default": 0 | ||
}, | ||
"labelHeight": { | ||
"type": "number", | ||
"default": 0 | ||
}, | ||
"labelWidth": { | ||
"type": "number", | ||
"default": 0 | ||
}, | ||
"align": { | ||
"type": "string", | ||
"default": "wide" | ||
} | ||
}, | ||
"supports": { | ||
"html": false, | ||
"reusable": false, | ||
"multiple": false, | ||
"align": [ | ||
"wide" | ||
] | ||
}, | ||
"textdomain": "label-printing", | ||
"editorScript": "file:label-printing.js", | ||
"editorStyle": "file:./label-printing.css", | ||
"style": "file:./style-label-printing.css" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
/** | ||
* Figuren_Theater label_printing Blocks. | ||
* | ||
* @package figuren-theater/label-printing | ||
*/ | ||
|
||
namespace Figuren_Theater\Label_Printing\Blocks\Printing; | ||
|
||
use Figuren_Theater\Label_Printing\Patterns; | ||
|
||
/** | ||
* Render callback of the 'figuren-theater/label-printing' block. | ||
* | ||
* Shows a printable sheet with multiple same instances of the coosen label. | ||
* | ||
* @param array $attributes The blocks attributes. | ||
* | ||
* @return string | ||
*/ | ||
function render( array $attributes ) : string { | ||
|
||
// Get the label post object based on the provided attribute. | ||
$label = \get_post( $attributes['wpLabelPost'] ); | ||
|
||
if ( ! $label instanceof \WP_Post ) { | ||
return ''; | ||
} | ||
|
||
// Define the pattern slug for the label. | ||
$pattern_slug = 'figuren-theater/label-view-a4-' . $label->ID; | ||
|
||
// Get the labels measurements. | ||
$meta = \get_post_meta( $label->ID, Patterns\META_KEY, true ); | ||
|
||
// Check if the metadata is valid. | ||
if ( ! \is_array( $meta ) || ! isset( $meta['height'] ) || ! isset( $meta['width'] ) ) { | ||
return ''; | ||
} | ||
|
||
// Generate Inline-CSS using a custom-property to set the labels printing dimensions. | ||
$css = \sprintf( | ||
'<style>:root { --label-printing-height:%smm;--label-printing-width:%smm; }</style>', | ||
$meta['height'], | ||
$meta['width'], | ||
); | ||
|
||
// Render the Inline-CSS and the block pattern with the specified pattern slug. | ||
return $css . \do_blocks( '<!-- wp:pattern {"slug":"' . $pattern_slug . '"} -->' ); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +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' => '6395cbb53da3629088d7'); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"$schema": "https://schemas.wp.org/trunk/block.json", | ||
"apiVersion": 3, | ||
"name": "figuren-theater/label-proxy", | ||
"version": "0.1.0", | ||
"title": "Label Proxy", | ||
"category": "widgets", | ||
"icon": "networking", | ||
"description": "Shows the content of the Label provided by the label-creator block, inside the print-sheet template for a given physical label.", | ||
"example": {}, | ||
"supports": { | ||
"html": false, | ||
"reusable": false, | ||
"inserter": false | ||
}, | ||
"textdomain": "label-printing", | ||
"editorScript": "file:label-proxy.js" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
/** | ||
* Figuren_Theater label_printing Blocks. | ||
* | ||
* @package figuren-theater/label-printing | ||
*/ | ||
|
||
namespace Figuren_Theater\Label_Printing\Blocks\Proxy; | ||
|
||
/** | ||
* Render callback of the 'figuren-theater/label-proxy' block. | ||
* | ||
* Works like a 'local reusable block' as long as we have no native one. | ||
* | ||
* @todo #12 Create a local-only reusable-block or a ‚reusable-block light‘ | ||
* | ||
* @return string | ||
*/ | ||
function render() : string { | ||
|
||
$post = \get_post(); | ||
|
||
$blocks = \parse_blocks( $post->post_content ); | ||
|
||
foreach ( $blocks as $block ) { | ||
|
||
/* // Works*/ | ||
if ( 'figuren-theater/label-printing' === $block['blockName'] ) { | ||
|
||
\ob_start(); | ||
foreach ( $block['innerBlocks'] as $block ) { | ||
|
||
echo \esc_html( \apply_filters( 'the_content', \render_block( $block ) ) ); | ||
} | ||
return \ob_get_clean(); | ||
|
||
break; | ||
|
||
} | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<?php return array('dependencies' => array('wp-blocks', 'wp-element', 'wp-i18n', 'wp-server-side-render'), 'version' => '118f2f1019f3791772f6'); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.