Newish to Layout Builder – we made a custom block plugin that renders a custom form. When I go to a page with Layout Builder and try to add that block… it is not in the list of blocks.
/**
* Provides a form block.
*
* @Block(
* id = "my_block",
* admin_label = @Translation("My Block with Form"),
* category = @Translation("Custom")
* )
*/
class MyBlock extends BlockBase implements ContainerFactoryPluginInterface {
/**
* The form builder.
*
* @var DrupalCoreFormFormBuilderInterface
*/
protected $formBuilder;
/**
* Constructs a new MyBlock instance.
*
* @param array $configuration
* The plugin configuration, i.e. an array with configuration values keyed
* by configuration option name. The special key 'context' may be used to
* initialize the defined contexts by setting it to an array of context
* values keyed by context names.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param DrupalCoreFormFormBuilderInterface $form_builder
* The form builder.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, FormBuilderInterface $form_builder) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->formBuilder = $form_builder;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('form_builder')
);
}
/**
* {@inheritdoc}
*/
public function build() {
$build['access_form'] = $this->formBuilder->getForm('DrupalmymoduleFormMyForm');
return $build;
}
}
Is there something I need to add to the annotation or class to make it an option for Layout Builder? It works fine as a normal Drupal block.
edit: I notice in one random custom module, they have to alter Layout Builder to get this functionality. Is that correct??