0

I want to create a module that allows creation multiple instances of blocks which render different graphic effects. The module should allow creation of unlimited blocks each with their own configuration.

Each block instance would have a dynamic form, which would allow selection of an effect type which would then dynamically provide form configuration settings for that effect.

The custom block plug in classes seem to be geared towards single instances blocks. There are some examples of using derivatives to create multiple instances

The logical way to do this however would seem to be via creating a 'custom block TYPE' programatically with it's own settings and custom display code. (As this is the purpose of custom block types after all).

It would need a dynamic form (updating when choosing the effect type) and it's own display code which includes the correct libraries and configuration per effect.

There are multitudes of examples of creating standard single use block plug ins. But nothing for programatically creating custom block types. Here is the only example I have found :

[https://drupal.stackexchange.com/questions/289724/how-can-i-programmatically-create-a-block-type][1]

Does anyone have any examples where they have done this? Or is this the wrong approach entirely?

1 Answers1

0

It's possible to convert a custom block on a custom block type by changing the file name

  - src/Plugin/Block/CustomBlock.php
  + src/Plugin/Block/CustomBlockType.php

and the class on it

- class CustomBlock extends BlockBase {
+ class CustomBlockType extends BlockBase  {

I hope it helps.

  • Thanks zarabatana. Doesn't this just change the name? Do you know of any examples of programatically creating a CustomBlockType? – Julian Thompson Oct 13 '22 at 16:38