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.

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

Downloads