Download the PHP package pollora/block-bindings without Composer
On this page you can find all versions of the php package pollora/block-bindings. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download pollora/block-bindings
More information about pollora/block-bindings
Files in pollora/block-bindings
Package block-bindings
Short Description WordPress Block Bindings declared with attributes: a #[BlockBinding] class is a source, its methods are fields, and the post meta, term meta, author meta and options Pollora ships are ready to bind. Runs with or without Laravel.
License MIT
Homepage https://pollora.dev/blocks/block-bindings/
Informations about the package block-bindings
WordPress Block Bindings declared in code: a class with #[BlockBinding] is a source, each method with #[BindingField] is a field a block attribute can be bound to, and the package registers it with WordPress, resolves the value on the page, previews it in the block editor and lists the fields the editor offers. It also ships four sources ready to bind: the post meta, the term meta and the author meta of pollora/meta, and the options a project lists.
Part of Pollora, the Laravel framework for WordPress, where it is installed and wired for you: see Block Bindings. It runs without Laravel too: in a plugin, a Bedrock site or any PHP project.
Installation
Requires PHP 8.3+ and WordPress 6.5+. It builds on pollora/meta, pollora/attributes, pollora/discovery and pollora/hook.
Declaring a source
A field returns a string, an int, a float, a bool, a Stringable (an object with a toHtml() method is written as HTML) or null to keep what the block holds. A method receives the BindingContext (the post, term and block of the context, the arguments of the binding, post(), meta()) and the services its other typed parameters name. A class with __invoke is a single-field source.
Wiring it outside Pollora
The sources are made by a PSR-11 container: give the resolver one that knows them (the dependencies of your own sources, and the shipped ones you register). Then register the shipped sources and let discovery find yours:
$visibility (WordPressContentVisibility) decides whether the visitor may see a post or a term, and $presenter (WordPressValuePresenter) escapes and words a value; both are WordPress adapters of the package. The pollora/option source reads only the options you pass to OptionSource, and the editor learns the fields through BindingEditorData, the ResolveBindingsController (the preview route) and WordPressBindingEditorScript. A method's services are given by ReflectionMethodInvoker (the container's, or a class that needs no argument); give the resolver a MethodInvokerInterface to inject differently.
The Laravel side stays in the framework: the service provider, config/block-bindings.php, pollora:binding:list and pollora:make:binding, the pollora:doctor check, and the injection of method parameters through Laravel's container.
Testing
License
MIT. See LICENSE.
All versions of block-bindings with dependencies
pollora/attributes Version ^0.1.1 || ^1.0
pollora/colt Version ^10.0.1
pollora/discovery Version ^0.1 || ^1.0
pollora/hook Version ^2.0.1
pollora/meta Version ^0.1
psr/container Version ^2.0
psr/log Version ^3.0