generated from figuren-theater/new-ft-module
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce block (and everything related) to print labels
- Loading branch information
1 parent
c331c35
commit b6b2e85
Showing
29 changed files
with
809 additions
and
3 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
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.
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
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" | ||
} |
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,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 . '"} -->' ); | ||
} |
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 @@ | ||
<?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.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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" | ||
} |
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,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; | ||
|
||
} | ||
} | ||
|
||
} |
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 @@ | ||
<?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.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# multiple-blocks-template | ||
|
||
This template will scaffold a plugin that is set up for registering multiple blocks in a single plugin create using the [`@wordpress/create-block`](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-create-block/) tool. | ||
|
||
## Usage | ||
Run the following in the terminal of your choice: | ||
|
||
`npx @wordpress/create-block example-plugin --template @ryanwelcher/multiple-blocks-template` | ||
|
||
The name of the plugin ( example-plugin in the example above) is used as both the name of the plugin and the name of the block being created. This is due to the current `@wordpress/create-block` tool expecting a single block per plugin. | ||
|
||
|
||
## Structure | ||
|
||
Once the command has completed, the following structure will be created. | ||
|
||
``` | ||
- assets - this contains an internal template for subsequent blocks | ||
- build | ||
- src | ||
--> block-editor | ||
---> blocks | ||
----> {example-block} | ||
-----> block.json | ||
-----> edit.js | ||
-----> editor.scss | ||
-----> index.js | ||
-----> save.js | ||
-----> style.scss | ||
.editorconfig | ||
.eslintrc | ||
.gitignore | ||
{example-block}.php | ||
package.json | ||
package-lock.json | ||
webpack.config.js | ||
``` | ||
|
||
### Adding another block requires the following steps: | ||
|
||
1. From the root of the plugin, cd into the includes/block-editor/blocks directory | ||
2. Run the following command: `npx @wordpress/create-block --template ../../../assets | ||
3. Add a new entry point in `webpack.config.js` that points to the new block. | ||
4. ~~Update the `$blocks` array in the main plugin php file to include the new block.~~ | ||
5. Update the editorScripts, editorStyles, and styles items in the newly added block. |
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,39 @@ | ||
{ | ||
"$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" | ||
} |
Oops, something went wrong.