Early Bird Registration for DrupalCon Atlanta is now open! By registering during our Early Bird Registration window, you’ll save $100. This window ends on 19 January 2025 and will go by quickly, so don’t wait!
This project is not covered by Drupal’s security advisory policy.
Display blocks based on "configuration-born behavior objects" via cfr plugins and cfr plugin presets.
Block plugins created this way can be instantiated more than once, and possibly used in other places than just the core block system.
Why?
You get
- configurable block types
- possibility for more than one instance of the same type, each with different configuration.
- exportable with features
- use the same render array provider as a block or elsewhere, using the adapter for BuildProviderInterface.
How to (site builder):
- Install module + dependencies.
- Install renderkit
- Ideally, enable cfrplugindiscovery (already downloaded with dependencies above)
- Go to admin/structure/cfrpreset
- Create one or more preset for "BlockInterface".
- Go to admin/structure/block. The presets you just created will appear there as blocks.
Existing plugins
Existing BlockInterface plugins:
Currently only one: "Build provider". THis is an adapter plugin. It allows to pick any build provider plugin, and use it as a block.
Existing BuildProviderInterface plugins:
These all come from renderkit. So this list may be incomplete.
- Views display.. (any views display, not just "block")
- Sequence of build providers: Choose multiple inner build providers, and a list format to control the wrapper html.
More implementations might appear in the future. E.g.
- Menu (sub)tree, similar to menu_block or menupoly.
And you can write your own.
How to (developer):
In a custom module..
- Create an src/ subfolder to organize your classes with PSR-4, like Drupal 8 modules do it.
- Implement hook_cfrplugin_info(). Call cfrplugindiscovery(), similar to how renderkit_cfrplugin_info() does it.
- Implement
\Drupal\cfrplugin\Block\BlockInterface
like below. Annotate it with@CfrPlugin(id, label)
. - Look into renderkit for more advanced code examples.
<?php
namespace Drupal\MODULE_NAME;
use Drupal\cfrblock\Block\BlockInterface;
/**
* @CfrPlugin("hello", "Hello world")
*/
class Block_Hello implements BlockInterface {
/**
* @return array
* Format: ['subject' => '..', 'content' => [..]]
*
* @see hook_block_view()
*/
public function view() {
return [
'subject' => t('Hello world'),
'content' => [
'#markup' => t('Yolo.'),
],
];
}
}
?>
Project information
- Module categories: Developer tools
- Created by donquixote on , updated
- This project is not covered by the security advisory policy.
Use at your own risk! It may have publicly disclosed vulnerabilities.